如何在python中循环此代码
我如何循环它,以便它在电子邮件无效时请求另一封电子邮件我建议您稍微重构一下代码:如何在python中循环此代码,python,loops,Python,Loops,我如何循环它,以便它在电子邮件无效时请求另一封电子邮件我建议您稍微重构一下代码: EmailAddress= input("What is your Email?") import re def Find (codePattern, Email): match = re.search(codePattern,Email) if match: print ('Valid Email Address' , match.group()) else: print ('Invali
EmailAddress= input("What is your Email?")
import re
def Find (codePattern, Email):
match = re.search(codePattern,Email)
if match: print ('Valid Email Address' , match.group())
else: print ('Invalid Email Address')
Find ('^\w+@+\w+\.+\w+', EmailAddress)
简单的方法是使用break in
if
或者继续无限循环。我认为没有必要使用bool(),所以搜索def check\u email(\uuuuu,\uuuuu):返回重新搜索(模式,email)
def check_email(email, pattern='^\w+@+\w+\.+\w+'):
return re.search(pattern, email)
email = input("What is your Email?")
while not check_email(email):
print("Invalid, please try again.")
email = input("What is your Email?")