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:
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.96001Step by Step Solution
There are 3 Steps involved in it
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started