Advertisement
TizzyT

Python Assignment 2

Nov 15th, 2016
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.22 KB | None | 0 0
  1. #Predefined List
  2. Weather = ['Monday 42', 'Tuesday 45', 'Wednesday 86', 'Thursdays 75', 'Friday 43', 'Saturday 73', 'Sunday 29']
  3.  
  4. #Calculation functions
  5. def CalcLow(List):
  6.     CrntLowTemp = int(List[0].split()[1])
  7.     for temps in List:
  8.         Working = int(temps.split()[1])
  9.         if Working < CrntLowTemp:
  10.             CrntLowTemp = Working
  11.     return CrntLowTemp
  12.  
  13. def CalcHigh(List):
  14.     CrntHighTemp = int(List[0].split()[1])
  15.     for temps in List:
  16.         Working = int(temps.split()[1])
  17.         if Working > CrntHighTemp:
  18.             CrntHighTemp = Working
  19.     return CrntHighTemp
  20.  
  21. def CalcAverage(List):
  22.     AVG = 0
  23.     for temps in List:
  24.         AVG += int(temps.split()[1])
  25.     return AVG / len(List)
  26.  
  27. #Print functions
  28. def PrintWeather(List):
  29.     for element in List:
  30.         Parts = element.split()
  31.         print(Parts[0] + '\n' + Parts[1] + '\n')
  32.  
  33. def PrintHigh(List):
  34.     print('The High is\n' + str(CalcHigh(List)) + '\n')
  35.  
  36. def PrintLow(List):
  37.     print('The Low is\n' + str(CalcLow(List)) + '\n')
  38.  
  39. def PrintAverage(List):
  40.     print('The Average is\n' + '{0:.2f}'.format(CalcAverage(List)) + '\n')
  41.  
  42. #Output
  43. PrintWeather(Weather)
  44. PrintLow(Weather)
  45. PrintHigh(Weather)
  46. PrintAverage(Weather)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement