Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. import requests
  2. import csv
  3.  
  4. def download_files():
  5.     #This function creates two .dat files necessary for further calculations
  6.  
  7.     weather_source = requests.get('http://codekata.com/data/04/weather.dat')
  8.     football_source = requests.get('http://codekata.com/data/04/football.dat')
  9.  
  10.     with open('weather.dat', 'wb') as f:
  11.         f.write(weather_source.content)
  12.  
  13.     with open('football.dat', 'wb') as f:
  14.         f.write(football_source.content)
  15.  
  16. def smallest_temperature_difference():
  17.     weather = open('weather.dat')
  18.  
  19.     weather_data_list =[]
  20.  
  21.     for line in weather:
  22.         weather_data_list += [line.split()]
  23.  
  24.     separate_days_data = [x for x in weather_data_list[2:]]
  25.     temperatures_list = [x[:3] for x in separate_days_data[:-1]]
  26.     numeric_lists = [[elem.replace('*', '') for elem in lst] for lst in temperatures_list] #Remove asterisks from string
  27.     values = [[int(x) for x in sublist] for sublist in numeric_lists]
  28.     max_temperatures = [x[1] for x in values]
  29.     min_temperatures = [x[2] for x in values]
  30.     subtraction_results = [x - y for x, y in zip(max_temperatures, min_temperatures)]
  31.     day_with_smallest_temp_spread = subtraction_results.index(min(subtraction_results))+1
  32.  
  33.     print('Day with smallest temperature spread is day number', day_with_smallest_temp_spread)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement