How do I loop User Input? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How do I loop User Input?

Im trying to get this email validator to keep asking for user input.. at the moment it just displays the no dice error infinitley until exit but i want it to ask for new input.. i cant quite get hte right combination lol.. Any Ideas? import re #import the reg expression module email = str(input("INput Email Address:")) #user inputs the email to be validated as a string check = email #email to verify from user input match = re.match('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})

#x27;, check) #checks the following expression to the inputted data while match == None: #while the email is invalid according to the re.match expression list..Notice "None" works but "False" Does not.. print ("No Dice, Please Enter a Valid Email Address: ") #message to explain the error #loop back to the start here .. to retry until a coorect email is inputted if True: #if everything is ok with the email address print ("Email Is Valid") #print a message to say whats what print (email) #print the email email = str(input("INput Email Address:")) https://code.sololearn.com/cz37umo7HB4y/#py

18th Apr 2017, 11:22 PM
John Ashurst (Maffas)
John Ashurst (Maffas) - avatar
1 Answer
+ 1
update: change if to else https://code.sololearn.com/cz37umo7HB4y/#py ************************************** import re #import the reg expression module email = str(input("INput Email Address:")) #user inputs the email to be validated as a string check = email #email to verify from user input match = re.match('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})
#x27;, check) #checks the following expression to the inputted data while match == None: #while the email is invalid according to the re.match expression list..Notice "None" works but "False" Does not.. print ("No Dice, Please Enter a Valid Email Address: ") #message to explain the error else: #if everything is ok with the email address print ("Email Is Valid") #print a message to say whats what print (email) #print the emaiemail = str(input("INput Email Address:"))
18th Apr 2017, 11:29 PM
John Ashurst (Maffas)
John Ashurst (Maffas) - avatar