1. Engineering
  2. Computer Science
  3. ok this code suppose to save the data into a...

Question: ok this code suppose to save the data into a...

Question details

Ok this code suppose to save the data into a file but my code is just create a new file without saving any output to the file here is a pic describe what i mean:

2019-82-82 19:00:00 2019-82-82 22:00:00 2019-62-83 01:00 : ее 2019-82-83 04:80:86 2019-e2-83 7:00:00 2019-02-83 10:00:00 Enter location: jeddah 2019-01-29 13:00:00 2019-81-29 16:00:00 2019-81-29 19:00:00 2019-61-29 22:00:00 2019-81-30 01:80:86 2019-e1-30 4:00:00 2019-01-30 7:00:00 2019-01-30 10 : 00 : 00 2019-01-38 13:00:00 2019-91-30 16: 00 : 2019-91-3θ 19: 00 : 2019-61-3e 22:00:00 2019-81-31 01:80:86 2019-01-31 04:80:00 2019-01-31 07:00:00 2019-01-31 10:00:00 2019-01-31 13:00:00 2019-91-31 16: 00 : 2019-91-31 19: 00 : 2019-61-31 22:00:00 2819-82-81 01:00:06 2019-82-81 04:80:06 2019-92-91 07:00:00 5.28 4.53 -3.74 θ.97 get_weather (api _key, location): rrequests.get (url) return r.Json( 1.62 2.95 25.36 24.94 main ): E-open (output.cat while True: output.txt - Notepad File Edit Format View Help

And here is the code:

import requests
from datetime import datetime


def get_weather(api_key, location):
url = "https://api.openweathermap.org/data/2.5/forecast?q={}&units=metric&appid={}".format(location, api_key)
r = requests.get(url)
return r.json()

def main():
f = open('output.txt', 'w')
while True:
location = input('Enter location: ')
if location == 'EXIT':
f.write('')
f.close()
return

api_key = '2b92ac90c161a8b52a86175509113de9'
weather = get_weather(api_key, location)

prediction = weather['list']
f.write('location: ' + location + '')
for day in prediction:
s = '%-40s%.2f' % (str(datetime.fromtimestamp(day['dt'])), day['main']['temp'])
f.write(s + '')
print(s)

main()

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution