Advertisement
silver2row

testing_Python3_and_built_ins.py

Sep 8th, 2024
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.07 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. # Reading from Weather.txt and making adjustments
  4.  
  5. y = 0
  6. m = 0
  7.  
  8. #### Read in Data ####
  9. filename = open("Weather.txt", "r")
  10.  
  11. infile = filename.read()
  12.  
  13. #### Read Line from File ####
  14. datalist = []
  15.  
  16. for line in infile:
  17.     date = m, y
  18.     date = (line.split('-'))
  19.     #### Get Data from Line ####
  20.     m, y, h, l, r = (line.split(','), line.split(','), line.split(','), line.split(','), line.split(','))
  21.     highTemp = str(h)
  22.     lowTemp  = str(l)
  23.     rainfall = str(r)
  24.     #### Get Date Correct ####
  25.     month = str(m)
  26.     year  = str(y)
  27.     date = (month, year)
  28.  
  29.     #### Put data in a List ####
  30.     datalist.append([month, year, highTemp, lowTemp, rainfall])
  31.  
  32. # Close the File #
  33. filename.close()
  34.  
  35. #### Analyze the Data ####
  36. singlemonth = int(input("For the median of high-low temps and median rainfall, enter in the month of your choosing: "))
  37. singleyear  = int(input("Enter in your favorite year, i.e. as long as it is '22, '23, or '24: "))
  38.  
  39. # Search for Historical Data #
  40. gooddata = []
  41. for singlemonth in datalist:
  42.     if (singlemonth[0] == month) and (singlemonth[1] == year):
  43.         gooddata.append([(singlemonth[2] == highTemp), (singlemonth[3] == lowTemp), (singlemonth[4] == rainfall)])
  44.  
  45. # Perform Analysis #
  46. minsofar     = 0
  47. maxsofar     = 0
  48. numgooddates = 0
  49. sumofmin     = 0
  50. sumofmax     = 0
  51. rainfall_One = 0
  52. for singlemonth in gooddata:
  53.     numgooddates += 1
  54.     sumofmin += (singlemonth[0])
  55.     sumofmax += (singlemonth[1])
  56.     if (singlemonth[1]) < minsofar:
  57.         minsofar += (singlemonth[1])
  58.     if (singlemonth[2]) > maxsofar:
  59.         maxsofar += (singlemonth[2])
  60.  
  61. avgLow  = sumofmin / numgooddates
  62. avgHigh = sumofmax / numgooddates
  63. rain_percent = rainfall_One / numgooddates * 100
  64.  
  65. #### Present the Results ####
  66. print("There were", numgooddates - 1, "days")
  67. print("The lowest temperature on record was", minsofar)
  68. print("The highest temperature on record was", maxsofar)
  69. print("The average high was", avgHigh)
  70. print("The average low was", avgLow)
  71. print("The chance of rain during this year was", rain_percent, "%")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement