Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python中循环此代码_Python_Loops - Fatal编程技术网

如何在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?")