Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Here is the picture of the problem:

image text in transcribed

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()

Command Prompt icrosoft Windows [Uersion 6.3.96001 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>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Analysis Using SQL And Excel

Authors: Gordon S Linoff

2nd Edition

111902143X, 9781119021438

More Books

Students also viewed these Databases questions