+ 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
9 Respostas
+ 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")
+ 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")
+ 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
+ 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")
0
I undersant
https://code.sololearn.com/cIqWsrYxGOC8/?ref=app
0
try:
x = int(input())
print(menu[x])
print("Thanks for your order")
except (IndexError, ValueError, TypeError):
print("Item not found")
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")
- 1
Giovanni Reale
https://code.sololearn.com/cXEwcLdwRFL7/?ref=app
May be this can help you
- 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