0
ValueError wonât work
In the following code, I canât get the ValurError to produce the desired output âItem not foundâ. Iâve tried everything that I can think of. The rest of the program works fine, just not that. Iâd appreciate any feedback you can give. menu = ['Fries', 'Sandwich', 'Cheeseburger', 'Coffee', 'Soda'] order = int(input()) try: print(menu[order]) except ValueError: print("Item not found") except IndexError: print("Item not found") else: print("Thanks for your order")
3 RĂ©ponses
+ 6
A ValueError I believe occurs when you try to convert to int what cannot be interpreted as number. But that code line is outside the try-block. Put the try before order = int(input()).
+ 5
# Put the try before order = int(input())
https://code.sololearn.com/c3nawUtZndaI
+ 3
Thank you Ani Jona đ and SoloProg that instantly solved my problem, thank you so much.
Such a simple fix to something that had me chasing my tail for hours (aussie saying for running around in circles).
Have an amazing week đ
Thank you again.