I am trying to make a simple calculator and want to return to the beginning of the loop if an unallowed value, like negative numbers, is input. However, I cannot figure out how to return to the beginning of the loop while already midway through without any errors.
This is what I have so far:
while True:
try:
height = float(input("Enter the height of the cylinder. "))
if height <0:
print("Only enter positive numbers.")
else:
radius = float(input("Enter the radius of the cylinder. "))
if radius <0:
print("Only enter positive numbers.")
finally:
volume = height*3.14159*radius**2
print("The volume of the cylinder is",volume,"units")
I have tried searching and haven't been able to understand the other answers.