Asking user input until they give good response | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Asking user input until they give good response

While True: name = input("what is your name" ) Assert len(name) > 2 , (name is short) : Continue #again asks question Break # break loop and run further program ----- I want my program to behave like this But it doesn't and don't know a way how it can ----- I know there should not ':' in assert but i typed this to show how i want my program to behave

22nd Aug 2020, 10:27 AM
Kairav Bhatia
Kairav Bhatia - avatar
3 Answers
+ 7
a = int(input()) while a != 10: a = int(input()) print(a) This will keep on asking input from the user until the system gets 10. If the system gets 10, the loop will break and 10 will be printed
22nd Aug 2020, 10:33 AM
Namit Jain
Namit Jain - avatar
+ 5
notInt = True while notInt: a = input() try: a = int(a) notInt = False except: continue print(a)
22nd Aug 2020, 11:53 AM
Namit Jain
Namit Jain - avatar
+ 1
Is it also possible to check input type?? As i want user to only input integer and if they inputs string it will ask again
22nd Aug 2020, 11:50 AM
Kairav Bhatia
Kairav Bhatia - avatar