I was writing a basic program in python to prompt user for their height and weight. If they enter a negative number I want it to loop until they enter a value that is positive. I wanted to know if this code could be improved upon:
while True:
height = eval(input("Please enter your height in inches: "))
if height > 0:
break
elif height <= 0:
print("Invalid entry.")
while True:
weight = eval(input("Enter your weight in pounds: "))
if weight > 0:
break
elif weight <= 0:
print("Invalid entry.")
I tried combining it into one while loop but I think the if/elif statements start to become an issue. Does anyone have advice to make this cleaner?