Trying to solve chef's kiss in intermediate python | Sololearn: Learn to code for FREE!

+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

3/30/2021 11:25:24 AM

Simisola Osinowo

8 Answers

New Answer

+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.

+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")

+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")

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")

0

When i tried this an error popped up which was Bad except clauses order(empty clause should always appear last)

0

I am not finding any error here(my code).

0

Thanks it has worked

0

I Have used: ... except(ValueError, TypeError, IndexError): ... And it works!