Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Weather data from Cambridge UK (Source: https://www.ncdc.noaa.gov/)
- # set up functions to take the relevant list
- def minimum(the_list):
- value = sorted(the_list)[0]
- return value
- def maximum(the_list):
- value = sorted(the_list, reverse=True)[0]
- return value
- def mean(the_list):
- total = 0
- for x in range(len(the_list)):
- total += the_list[x]
- value = round(total/len(the_list), 2)
- return value
- # list the 3 data sets
- max_temps = [8,9,12,15,18,21,23,23,20,16,11,8]
- min_temps = [2,2,3,5,8,11,13,13,10,8,4,2]
- rain_days = [10,8,7,7,8,8,8,9,6,8,10,8]
- # menu to choose which data set to work on
- print("Which data would you like to work with? Select option 1, 2 or 3 below:\n")
- the_choice = input("1: Maximum monthly temperatures\n2: Minimum monthly temperatures\n3: Number of rainy days\n\n> ")
- if the_choice == "1":
- the_list = max_temps
- elif the_choice == "2":
- the_list = min_temps
- elif the_choice == "3":
- the_list = rain_days
- else:
- print("Invalid selection")
- # Establish which procedure is needed
- print("For this data set, would you like to know the maximum value, minimum value or average value?")
- the_choice = input("1: Maximum value\n2: Minimum value\n3: Average value\n\n> ")
- if the_choice == "1":
- print("\nThe maximum value is: " + str(maximum(the_list)))
- elif the_choice == "2":
- print("\nThe minimum value is: " + str(minimum(the_list)))
- elif the_choice == "3":
- print("\nThe mean value is: " + str(mean(the_list)))
- else:
- print("\nInvalid selection")
- print()
Advertisement
Add Comment
Please, Sign In to add comment