25th Dec 2023, 8:36 AM
P A Arrchith Iyer
P A Arrchith Iyer - avatar
2 Antworten
+ 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