Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- # Reading from Weather.txt and making adjustments
- #### Read in Data ####
- filename = input("Please enter in your file name for data conversion: ")
- infile = open(filename, 'r')
- #### Read Line from File ####
- datalist = []
- for line in infile:
- #### Get Data from Line ####
- date, h, l, r = (line.split(','))
- highTemp = int(h)
- lowTemp = int(l)
- rainfall = float(r)
- #### Get Date Correct ####
- month, year = (date.split('-'))
- month = int(m)
- year = int(y)
- #### Put data in a List ####
- datalist.append([month, year, highTemp, lowTemp, rainfall])
- # Close the File #
- infile.close()
- #### Analyze the Data ####
- month = int(input("For the median of high-low temps and median rainfall, enter in the month of your choosing: \n"))
- year = int(input("Please enter the year of 2024! "))
- # Search for Historical Data #
- gooddata = []
- for singleday in datalist:
- if (singleday[0] == month) and (singleday[1] == year):
- gooddata.append([singleday[2], singleday[3], singleday[4], singleday[5]])
- # Perform Analysis #
- minsofar = 120
- maxsofar = -100
- numgooddates = 0
- sumofmin = 0
- sumofmax = 0
- for singlemonth in gooddata:
- numgooddates += 1
- sumofmin += singleday[1]
- sumofmax += singleday[2]
- if singlemonth[1] < minsofar:
- minsofar = singleday[1]
- if singlemonth[2] > maxsofar:
- maxsofar = singleday[2]
- avgLow = sumofmin / numgooddates
- avgHigh = sumofmax / numgooddates
- #### Present the Results ####
- print("There were", numgooddates, "days")
- print("The lowest temperature on record was", minsofar)
- print("The highest temperature on record was", maxsofar)
- print("The average high was", avgHigh)
- print("The average low was", avgLow)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement