I am fairly new to Python and I'm trying to create a simple program to calculate, then print, how much a vacation rental is based on the number of weeks a user has inputted (so long as the number of weeks is greater than 4, but less than 16). I have that part of the code down just fine, but what I am having trouble with is getting the program to repeat the question if a user does enter a number that is not in range. Any help would be greatly appreciated. Here is my code:
weeks = 0
total = 0
while True:
try:
weeks = int(input("How many weeks do you plan on vacationing? "))
break
except ValueError:
print("Please enter a number.")
if weeks < 4:
print("Not in range.")
elif weeks <= 6:
total = weeks*3080
print("Rental cost: $",total)
elif weeks <= 10:
total = weeks*2650
print("Rental cost: $", total)
elif weeks <=16:
total = weeks*2090
print("Rental cost: $", total)
else:
print("Not in range.")
Update:
weeks = 0
total = 0
while True:
try:
weeks = int(input("How many weeks do you plan on vacationing? "))
if weeks < 4:
print("Not in range.")
continue
elif weeks <= 6:
total = weeks*3080
print("Rental cost: $",total)
break
elif weeks <= 10:
total = weeks*2650
print("Rental cost: $", total)
break
elif weeks <=16:
total = weeks*2090
print("Rental cost: $", total)
break
else:
print("Not in range.")
except ValueError:
print("Please enter a number.")