Mar-19-2018, 01:59 AM
Hello Everyone, I am learning how to make and use lists in python. I have a simple program made and I am struggling at the point when trying to get a sum of all the "user inputs" that are stored in my list. Can someone drop me a hint? I'd like to get a total and a sum of my user inputs as seen in the following code.
# This program will ask a user to enter rainfall data for # the twelve months in a year. It will take the user’s input # and return the rainfall total, and the annual average. # Declare constant integer SIZE = 12 def main(): # Create a list to hold the values of rainfall each month # as given by the user monthlyRain=[SIZE] # Create a variable to use as the counter months=0 # Ask the user to input data for 12 months of rainfall enterRain() # Calculate and display the total and average rainfall rainStats(monthlyRain) # The enterRain module will ask the user for 12 months of rainfall data # and store the data in a list called monthlyRain def enterRain(): for months in range(SIZE): print(int(input("Please enter rainfall for month " + \ str(months+1) + ":"))) months += 1 # The rainStats module will calculate the # total rain for the year and the # overall average. def rainStats(monthlyRain): total=0 for num in monthlyRain: total += num print("The total rainfall for the year is: " , total, "inches") average = total/12 print("The average rainfall for the year is: " , average, "inches") main()