1. Engineering
  2. Computer Science
  3. there is a problem with this code in python please...

Question: there is a problem with this code in python please...

Question details

there is a problem with this code in python please can you help to fix:

Here is the picture of the problem:

Command Prompt icrosoft Windows [Uersion 6.3.96001 <c) 2013 Microsoft Corporation. All rights reserved. Users sameercd CUe sameer DownloadsPrograming languages C311 UsersseerDown loads Programing languages C311>python.py File C:\Users\saneer\Downloads\Programing languages C311xpython.py, line 1, Traceback (most recent call last>: import requests oduleNotFoundError No module named requests NUserssameerDownloads Programing languages C311>

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.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