Can anyone help me with this else and handling challenge bon appetit. | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 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") ❤️ 🙏

2nd Mar 2022, 3:05 PM
Chelsie Herr
Chelsie Herr - avatar
4 ответов
+ 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")
2nd Mar 2022, 3:32 PM
Lothar
Lothar - avatar
+ 1
If could hug 🫂 you! Lothar
3rd Mar 2022, 12:55 AM
Chelsie Herr
Chelsie Herr - avatar
0
Drop the code so it can be preview
2nd Mar 2022, 3:13 PM
T.Coded
T.Coded - avatar
0
😎👏
3rd Mar 2022, 12:04 PM
ROMina Sirosi
ROMina Sirosi - avatar