+ 3
In Phyton, how to make a limited choice of the input ? For example, the code can only accept the input 1 or 2 or 5.
7 Antworten
+ 5
Jan Markus please help to run your code on IDE,it gives error.
+ 5
Jan Markus thanks,I"ll try it later.
+ 3
za = int(input(""))
if za == 1:
print('1')
elif za == 2:
print('2')
elif za == 5:
print('5')
else:
print("invalid input")
+ 2
Using conditions (if statements), Python has an ‘in’ operator which checks if a collection like a list has a specific item in it. You can have all acceptable input in a list then check if user input is in there using in operator. e.g.
https://code.sololearn.com/cfx58JbLHtX7/?ref=app
Note: this wont work well in Sololearn
+ 2
print('1, 2 or 3?')
while True:
x=input()
if x in ('1', '2', '3'):
break
+ 2
Jan Markus Da bist Du ja wieder. Wir haben Dich schon vermisst. Siehe Kommentare zu
https://code.sololearn.com/cAM1YUq9RVQa/?ref=app
+ 1
Thank You LONGTIE