0

How to close if statements?

I have a program which able to check if an email is valid or not but I have many "if" statements which need to be checked in the same time and now I can't print out if the email is correct. Can I replace if for something else (not elif) or anything that can help? (It's important to not use regex for checking) https://code.sololearn.com/cq0o0IS8jyuv/?ref=app

30th Mar 2022, 1:31 PM
Tsunugi
Tsunugi - avatar
5 Answers
0
You have indentation errors and invalid characters errors If you want close an if statement, you can just go to the next line and don't add spaces. Like this: if True: print('inside if') #here you closed the if statement print('outside if')
30th Mar 2022, 1:45 PM
Stefanoo
Stefanoo - avatar
0
Stefanoo I'd like if it would print "valid" only if every other statement is false. An elif could help in this but I need to check every statements so I can get every error message. For example: input: he@@llo.worldcom >>> output: "too much @", "wrong domain name" etc.
30th Mar 2022, 1:58 PM
Tsunugi
Tsunugi - avatar
0
Prince Kumar I mentioned that I can't use regex, because that's a condition for the practice I do.
30th Mar 2022, 1:59 PM
Tsunugi
Tsunugi - avatar
0
You could use a bool before all if statements and if any if is false it sets the bool on false. valid = True if... valid = false if... valid = false if... valid = false if... valid = false if valid: # do stuff
30th Mar 2022, 2:05 PM
Stefanoo
Stefanoo - avatar
0
This idea might work for you: Initialize an error string variable to null string. Instead of immediately printing each error message, append the error message to the error string variable. After all the validations are tested check the length of the error string. If the length is zero, then print the valid email message, else print the error string. And be sure to clean up all the spurious non-printable and invalid characters that are preventing the code from running. Such characters get embedded when you copy/paste code from an outside source like a UTF-16 text editor.
31st Mar 2022, 5:46 AM
Brian
Brian - avatar