Intermediate · Text processing · 159 of 264
Simple email check
Check an email address: exactly one @, something before it, and after it a dot with text on both sides (e.g. name@school.org). No spaces.
Input: one line. Output: valid or invalid
Examples
Input
name@school.org
Output
valid
Input
name.school.org
Output
invalid
Input
@school.org
Output
invalid
Input
a@b
Output
invalid
2 more tests check other inputs when you press Check.
Stuck? The idea behind text processing
Go through text a character at a time, and build the answer as you go: a new string, or a list of pieces joined at the end with "".join().
ord() gives a character's number and chr() the character for a number: useful for shifting letters.
text = input()
out = []
for ch in text:
out.append(ch.upper() if ch.islower() else ch.lower())
print("".join(out))Watch for: Shifting letters past "z" must wrap round to "a": use % 26 on the letter's position in the alphabet.