Why my code don't run all test case? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why my code don't run all test case?

You are making a digital menu to order food. The menu is stored as a list of items. Your program needs to take the index of the item as input and output the item name. In case the index is not valid, you should output "Item not found". In case the index is valid and the item name is output successfully, you should output "Thanks for your order". Sample Input: 2 Sample Output: Cheeseburger Thanks for your order https://code.sololearn.com/cJgPgtj7OkFz/?ref=app https://code.sololearn.com/cJgPgtj7OkFz/?ref=app https://code.sololearn.com/cJgPgtj7OkFz/?ref=app

18th Mar 2021, 6:24 PM
Giovanni Reale
Giovanni Reale - avatar
9 Answers
+ 8
menu = ['Fries', 'Sandwich', 'Cheeseburger', 'Coffee', 'Soda'] #your code goes here try: ask = int(input()) print(menu[ask]) except (IndexError, ValueError, TypeError): print("Item not found") else: print("Thanks for your order")
27th Aug 2021, 5:33 PM
Kevin
+ 2
menu = ['Fries', 'Sandwich', 'Cheeseburger', 'Coffee', 'Soda'] #your code goes here try: option = int(input()) print(menu[option]) except (IndexError, TypeError, ValueError): print("Item not found") else: print("Thanks for your order")
18th Feb 2022, 10:08 AM
Liria
Liria - avatar
+ 1
menu = ['Fries', 'Sandwich', 'Cheeseburger', 'Coffee', 'Soda'] while True: try: n = int(input()) n = menu[n] print(f'{n}') except: print("Item not found") else: print("Thanks for your order") break
15th Dec 2021, 1:52 AM
Samnith Vath
Samnith Vath - avatar
+ 1
menu = ['Fries', 'Sandwich', 'Cheeseburger', 'Coffee', 'Soda'] #your code goes here try: ask = int(input()) print(menu[ask]) except (IndexError, ValueError, TypeError): print("Item not found") else: print("Thanks for your order")
10th Nov 2022, 8:36 AM
Pooja Patel
Pooja Patel - avatar
18th Mar 2021, 6:44 PM
Giovanni Reale
Giovanni Reale - avatar
0
try: x = int(input()) print(menu[x]) print("Thanks for your order") except (IndexError, ValueError, TypeError): print("Item not found")
3rd Jan 2022, 2:19 PM
Nazarii Zavada
Nazarii Zavada - avatar
0
here is my code ! menu = ['Fries', 'Sandwich', 'Cheeseburger', 'Coffee', 'Soda'] #code is entered try: i=int(input()) print(menu[i]) except: print("Item not found") else: print("Thanks for your order")
2nd Dec 2023, 7:36 AM
vahid kamrani
vahid kamrani - avatar
19th Mar 2021, 7:17 AM
Scarlet Witch
Scarlet Witch - avatar
- 2
menu = ['Fries', 'Sandwich', 'Cheeseburger', 'Coffee', 'Soda'] ask = input() if ask=='0': print(menu[0]) print('Thanks for your order') elif ask=='1': print(menu[1]) print('Thanks for your order') elif ask=='2': print(menu[2]) print('Thanks for your order') elif ask=='3': print(menu[3]) print('Thanks for your order') elif ask=='4': print(menu[4]) print('Thanks for your order') else: print("Item not found") hope it will help you
2nd Aug 2021, 10:17 AM
Tanvi Kumari