0
Python err??? why??
sodas = ["pepsi", "cherry coke zero", "sprite"] chips = ["doritos", "fritos"] candy = ["snickers", "m&ms", "twizzlers"] while True: choice = input("would you like soda, some chips or a candy").lower() try: if choice == 'soda': snack = sodas.pop() elif choice == 'chips': snack = chips.pop() elif choice == 'candy': snack = candy.pop() else: print("sorry i didnt understand that. ") continue except IndexError: print("we are all out of {}! sorry!".format(choice)) else: print("here's your {}: {}".format(choice, snack))
4 odpowiedzi
+ 5
else:
print("here's...")
+ 3
sairam kamalay the "else" is with while-loop
but actually, it won't work because True is always True
0
Yes Flandre Scarlet . It's just an indentation error . Just remove the spaces before the else part. Thank you @Flandre Scarlet for mentioning the error.
0
Thanks so much