Python err??? why?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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))

12th Nov 2018, 5:24 PM
Shmuel israel Zilberman
Shmuel israel Zilberman - avatar
4 Answers
+ 5
else: print("here's...")
12th Nov 2018, 6:24 PM
Flandre Scarlet
Flandre Scarlet - avatar
+ 3
sairam kamalay the "else" is with while-loop but actually, it won't work because True is always True
12th Nov 2018, 6:30 PM
Flandre Scarlet
Flandre Scarlet - avatar
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.
12th Nov 2018, 6:34 PM
sairam kamalay
sairam kamalay - avatar
0
Thanks so much
14th Nov 2018, 5:03 PM
Shmuel israel Zilberman
Shmuel israel Zilberman - avatar