day13 practice

"" " 
5.1 verify the legality of e-mail string
requirements:
. @ 1. not contain before (in the bar) -, and other symbols such as $ &, but may contain, at the beginning of letters and numbers
2. Universal Naming is_valid_email ()
3. after @ number or letter
 suffix .com | .gov | .net any one end
reference: test the legality
1. [email protected] true
2. [email protected] true
3. [email protected] true
4 . [email protected] false
5. [email protected] true
"" "
Import Math
Import Re

DEF email_path_before_chack (STR):
IF Not the re.compile (" ^ [A-zA-Z0-9] [A- Z0-9-zA,] * $ '.' ') match (str):.
Print ( "e-mail address input error")
return False
return True

def email_path_last_chack(str):
Not the re.compile IF ( "^ [A-zA-Z0-9, '.'] * $") match (str.split () [0] "."):.
Print ( "E-mail Address input errors suffix ")
return False

IF not str.split (" ") [1] in [" COM "," GOV "," NET "]:.
Print (" E-mail Web site address input error ")
return False
return True

DEF is_valid_email (email_path ):
IF "@" not in email_path:
Print ( "the address format is incorrect, there is no @")
return
IF not email_path_before_chack (email_path.split ( "@") [0]):
return
IF not email_path_last_chack (email_path.split ( "@") [. 1]):
return
Print ( "{} is a valid email address."format (email_path))
return
DEF main ():
the while True:
email_path the INPUT = ( "Please enter the e-mail address: \ n")
if email_path == "exit":
BREAK
is_valid_email (email_path)
IF __name__ == "__main__":
main ()


program execution results

 

 

 

 

 

 

 



Guess you like

Origin www.cnblogs.com/lyy17759893807/p/12046307.html