+ 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
3 Respuestas
+ 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
+ 5
notInt = True
while notInt:
a = input()
try:
a = int(a)
notInt = False
except:
continue
print(a)
+ 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