#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()
Edward_6 0 Newbie Poster
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
Edward_6 0 Newbie Poster
Edward_6 0 Newbie Poster
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague
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.