Question: The template program for this lab is set to read input: an integer for a year number, and a series of floats in a list
The template program for this lab is set to read input:
- an integer for a year number, and
- a series of floats in a list variable called sun_hours. These floats in the sun_hours list represent the number of sun hours in an area, for every month of the input year.
The template program also defines a list variable called moths_of_year that contains strings representing the names of the months of the year.
(1) Add code to compute and output the average number of sun hours for all months of the input year. (Submit for 2 points)
(2) Add code to find and output the maximum number of sun hours for any month in the sun_hours list. Hint: use the the function max() for lists. Store the maximum value you found in a variable named max_sun_hours. (Submit for 1 point, so 3 points total)
(3) Add code to find and output the month of the year that had the maximum number of sun hours. To do that:
- first search the sun_hours list for the maximum value you found in part (2), and which should be stored in the variable max_sun_hours. Use the list method index() and assign the index returned by this method call to a variable named index_of_max
- then, print the element at position index_of_max from the list months_of_year. (Submit for 2 points, so 5 points total).
-
Enter year: 2017 Enter sun hours: 69.3, 64.5, 161.4, 168.4, 226.1, 203.3, 212.3, 190.6, 163.7, 109.7, 73.5, 61.5 There were 142.025 hours of sun monthly in 2017. The sunniest month of 2017 had 226.1 of sun hours. The sunniest month of 2017 was May.

ACTIVITY3.4.1: LAB: List work 0/5 main.py Load default template... 1 # Do not modify this section of the program: 2 months of year-C January', 'February' 'March', April', May, June, July' August', September,October', 'November 3 yearint(input('Enter year ')) 4 sun-hours = [float(x) for x in input(' Enter sun hours : ').split(. ') ] 6 # FIXME (1): Compute and output the average number of sun hours for all months of the given year. 7 avg hours sum(sun_hours)/Men(sun_hours) 10 # FIXME (2): Find and output the maximum number of sun hours for any month of the given year. 11 smali = min(sun-hours) 12 13 # FIXME (3): Find and output the month of the year that had the maximum number of sun hours. 14 index_of_max
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
