It looks you are using python2. If you were using python3, you will get
what you have is close to what you want. You need to store the daily rain data in a list so that you can calculate average later.
ValueError
, not NameError
(line #9). See https://python-forum.io/Thread-Python3-2...-raw-input for more details. If this is the case you are strongly advised to switch to python3, because python2 support ends 1 January 2020.what you have is close to what you want. You need to store the daily rain data in a list so that you can calculate average later.
all_days = ("Monday", "Tuesday", "Wednesday", "Thursday","Friday", "Saturday", "Sunday") # number of weeks while True: try: total_weeks = int(input("Enter number of weeks for which rainfall should be calculated ")) except ValueError: print("Number of weeks must be an interger") else: if total_weeks < 1: print("Number of weeks must be at least 1") else: break daily_rain = [] for week in range(1, total_weeks+1): for day in all_days: rain = int(input("enter the rain for {} in week {}:".format(day, week))) # in 3.6+ this could be rain = int(input(f"enter the rain for {day} in week {week}:")) daily_rain.append(rain) # change the code above so that you can handle wron input for rain, i.e. you want number - int/float # add code to calculate average
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs