#Template for Program 6
#Complete the code in each module as discussed in
#the Program 6 Instructions

def main():
    #initialize variables so incomplete code won't cause errors
    #can be deleted once code is finished
    totalRainfall = 0
    minRainfall = 0
    maxRainfall = 0

    #prints the progam title and a blank line
    print("Rainfall Calculator with Array")
    print()

    #declares an empty array (list) called rainfall to
    #which you can append values with the append method
    rainfall=[]

    #for loop to loop from 0 to 11
    #remember the 1st element of an array is at subscript 0
    for index in range(12):

    #input rainfall for month and store as float in variable
     rainInput = float(input("Inches of rainfall for month #"+str(index+1)+": "))

    #STEP 1 - append the value in the variable to the array


    #STEP 2 - call the calcTotal() function and pass it the array
    #store the returned value in totalRainfall


    #calculate the average (total / 12) and store it in a variable
    avgRainfall = totalRainfall / 12

    #STEP 4 - call the findMin() function and pass it the array
    #store the returned value in minRainfall


    #STEP 6 - call the findMax() function and pass it the array
    #store the returned value in maxRainfall


    #print the total rainfall
    print("Total rainfall in inches:", totalRainfall)

    #print the average rainfall
    print("Average rainfall in inches:", avgRainfall)

    #print the month with the minimum rainfall
    print("Lowest rainfall in inches:", minRainfall)

    #print the month with the maximum rainfall
    print("Highest rainfall in inches:", maxRainfall)

#calcTotal loops thru the array and uses a running total
#to find the total rainfall
def calcTotal(array):
    total = 0
    #STEP 3 - insert your for loop code below



    #insert your code for Step 3 above
    return total

#findMin loops thru the array and finds the lowest rainfall
def findMin(array):
    minRain = array[0]
    #STEP 5 - insert your for loop code below



    #insert your for Step 5 above
    return minRain

#findMax loops thru the array and finds the highest rainfall
def findMax(array):
    maxRain = array[0]
    #STEP 7 - insert your for loop code below



    #insert your for Step 7 above
    return maxRain

#call main() to start program
main()

Recommended Answers

All 4 Replies

You forget to state your problem or question.

I am learning about python programming and need help writing and understanding about how this program work I will attached instructions thank you sir for your reponse

Here is the program instructions

Your for loop should look like this ...

#declares an empty array (list) called rainfall to
#which you can append values with the append method
rainfall = []
#for loop to loop from 0 to 11
#remember the 1st element of an array is at subscript 0
for index in range(12):
    #input rainfall for month and store as float in variable
    rainInput = float(input("Inches of rainfall for month #"+str(index+1)+": "))
    #STEP 1 - append the value in the variable to the array
    rainfall.append(rainInput)

# test
print(rainfall)

Notice that you need to indent the block of statements that belong to the for loop. The test print is temporary, it lets you know what the list looks like.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.