+ 1
Can anyone help me with this else and handling challenge bon appetit.
I want to use my code but I don't understand why it is not working to catch a value error. Should I raise one? I'm confused here is my code... code = input() #your code goes here try: for i in code: if i != int(): print("Order accepted") print("Bon appetit") break except: if i == int(): print("Enter only digits") â€ïž đ
4 Answers
+ 7
Chelsie Herr ,
the input has to be taken inside the try:... block. use int(input()) so it will try to converted the input to int. if this conversion fails, because the input contains some other characters like letters, spaces,...
this causes the except: ... block to execute
try:
code = int(input())
print("Order accepted")
print("Bon appetit")
except: # this captures all errors
except ValueError: # or you can take this to capture only ValueErrors
print("Enter only digits")
+ 1
If could hug đ« you! Lothar
0
Drop the code so it can be preview
0
đđ