0
whats the problem? and how can i make it with a while loop so it will run till the input is "exit"?
my_List = ["apple" , "orange" , "watermellon"] my_Input = input("what fruit do you want?\n") if 1 or 2 or 3 or 4 or 5 or 6 or 7 or 8 or 9 in my_Input: print("you can only write fruits! not Integers!") exit() else: if my_Input in my_List: print("we have " + my_Input) else: print("we dont have " + my_Input)
3 Answers
+ 1
thanks!
0
Using exception handling block for reading input,
my_List = ["apple" , "orange" , "watermellon"]
digits = "1234567890"
while True:
try:
my_Input = input("what fruit do you want?:")
except EOFError:
exit()
if my_Input == "exit":
exit()
print(my_Input)
for digit in digits:
if digit in my_Input:
print("you can only write fruits! not Integers!")
exit()
if my_Input.lower() in my_List:
print("we have " + my_Input)
else:
print("we dont have " + my_Input)
0
Could you please check whether that code is what you expect!
--------------------------------------------------------
my_List = ["apple" , "orange" , "watermellon"]
my_Input = input("what fruit do you want?\n")
while my_Input not in my_List:
if my_Input.isalpha():
print("we don't have " + my_Input)
elif isinstance(my_Input, int):
print("you can only write fruits! not Integers!")
my_Input = input("what fruit do you want?\n")
print("we have " + my_Input)