How can I handle the part from while True to the for? I need an exception that tells the user that he needs to enter a number (in case he accidentally types a string) or a value > 0. I tried converting the nyear to an int so it would raise a value error but this only lead to an error.
So how would you guys handle this?
def main():
nyear = int(raw_input('Enter the years: '))
i = 0
while True:
try:
intTarget = int(nyear)
except ValueError:
print 'Value needs to be a number and needs to be greater than 0'
nyear = int(raw_input('Enter the years: '))
for year in range(nyear):
for month in range(12):
rinch = float(raw_input('How many inches of rain: '))
i += rinch
total = i
tmonths = (month + 1) * (year + 1)
ravg = total/tmonths
print total, tmonths, ravg
main()