+ 1

Trying to solve chef's kiss in intermediate python

Here is the code i ran: menu = ['Fries', 'Sandwich', 'Cheeseburger', 'Coffee', 'Soda'] menu=input() try: print(menu) except (TypeError , ValueError): print("Item not foumd") else: print("Thanks for your order") I am stuck at this point

30th Mar 2021, 11:25 AM
Simisola Osinowo
Simisola Osinowo - avatar
10 Answers
+ 2
use try: n=int(input()) // if the input is valid it won't raise exception .if input isn't valid it will raise error . print(menu[n]) // if n>=length of menu it will raise exception otherwise it will print the order And use only except: to catch all types of error. Don't use menu for variable again as menu is already a list.
30th Mar 2021, 11:35 AM
TOLUENE
TOLUENE - avatar
+ 1
No i meant it menu = ['Fries', 'Sandwich', 'Cheeseburger', 'Coffee', 'Soda'] try: n=int(input()) print(menu[n]) except : print("Item not found") else: print("Thanks for your order")
30th Mar 2021, 11:47 AM
TOLUENE
TOLUENE - avatar
+ 1
This worked for me menu = ['Fries', 'Sandwich', 'Cheeseburger', 'Coffee', 'Soda'] #your code goes here Ui= (input()) try: print(menu[int(Ui)]) except(TypeError, ValueError,IndexError): print("Item not found") else: print("Thanks for your order")
19th May 2021, 8:39 AM
jordan fletcher
0
Is this what you meant menu = ['Fries', 'Sandwich', 'Cheeseburger', 'Coffee', 'Soda'] try: n=int(input()) print(menu[n]) except (TypeError , ValueError): print("Item not foumd") except (TypeError , ValueError ): print("Thanks for your order")
30th Mar 2021, 11:44 AM
Simisola Osinowo
Simisola Osinowo - avatar
0
When i tried this an error popped up which was Bad except clauses order(empty clause should always appear last)
30th Mar 2021, 11:55 AM
Simisola Osinowo
Simisola Osinowo - avatar
0
I am not finding any error here(my code).
30th Mar 2021, 11:58 AM
TOLUENE
TOLUENE - avatar
0
Thanks it has worked
30th Mar 2021, 12:35 PM
Simisola Osinowo
Simisola Osinowo - avatar
0
I Have used: ... except(ValueError, TypeError, IndexError): ... And it works!
14th Apr 2021, 6:52 PM
Václav Dostál
Václav Dostál - avatar
0
menu = ['Fries', 'Sandwich', 'Cheeseburger', 'Coffee', 'Soda'] try: order=int(input()) print(menu[order]) print("Thanks for your order") except (TypeError , ValueError, IndexError): print("Item not found")
3rd Feb 2022, 3:06 AM
Cameron Boon
Cameron Boon - avatar
0
menu = ['Fries', 'Sandwich', 'Cheeseburger', 'Coffee', 'Soda'] menu_index = input() try: print(menu[int(menu_index)]) except (TypeError, ValueError): print("Item not found") else: print("Thanks for your order")
15th Feb 2022, 3:32 PM
Mohammad Jamal Mahmoud Al Jadallah
Mohammad Jamal Mahmoud Al Jadallah - avatar