Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The following code is meant to compute the average amount of rain that fell in a

ID: 3697171 • Letter: T

Question

The following code is meant to compute the average amount of rain that fell in an area during Hurricane Sandy. The data is read from a file named "rainAmounts.dat". which contains the amount of rain that fell in inches in a local area, each on its own line in the file. The data file is complete. However, the code will not execute correctly. What is the problem? Fix the code so that it will execute correctly to display the correct result. Give an example of a formal parameter from the program above. Give an example of an actual parameter (should be different from answer to c above). Give an example of a function call from the program above. Give an example of a method call from the program above.

Explanation / Answer

# -*- coding: cp1252 -*- 02 03 def main(): 04 05 num_months = 12 06 07     #Definera lite listor 08     months = [0] * num_months 09     name_months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sept','Oct','Nov','Dec'] 10 11 12     #Funktion för räkna det totala från listan 13     def total(months): 14         total = 0 15 16         for num in months: 17             total += num 18         return total 19 20     #Få alla nummer från användaren 21     for index in range(num_months): 22         print 'Enter the amount of rain in', 23         months[index] = input(str(index + 1) + ': ') 24     print 'The total is', total(months), 'mm.' 25 26     #Genomsnittet 27     avarage = float(total(months)) / float(num_months) 28     print 'The avarage rainfall is', avarage, 'mm.' 29 30     #Översätt från siffror till månadernas namn 31       32 33     #Sortera listan 34     months.sort() 35       36     print 'Lowest is', months[0] 37       38     print 'Most is', months[11] 39       40 main()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote