How to write an exception if the user inputs nothing as an input | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
25th Dec 2023, 8:36 AM
P A Arrchith Iyer
P A Arrchith Iyer - avatar
2 ответов
+ 8
P A Arrchith Iyer , we can keep it simple. what we can do is to run the input in a loop, as long as python is raising an exeption. in the sample you can only exit from the loop when a valid number has been given. may be you also like give a special input for terminating the program and handle this. radius = None while not radius: try: radius = float(input("Enter the radius: ")) except ValueError: print('Value error - Please enter a number') now you can run the second input in a similar way and then continue with the program.
25th Dec 2023, 1:05 PM
Lothar
Lothar - avatar
+ 1
Thank you Lothar
25th Dec 2023, 4:11 PM
P A Arrchith Iyer
P A Arrchith Iyer - avatar