+ 2
How to write an exception if the user inputs nothing as an input
https://sololearn.com/compiler-playground/c5AOPN9wpDYO/?ref=app
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.
+ 1
Thank you Lothar