Python Weather App Presentation (1)
Python Weather App Presentation (1)
Your Name
Date
Introduction
• import requests
api_key = "YOUR_API_KEY"
city = input("Enter city name: ")
url = f"http://api.openweathermap.org/data/2.5/weather?
q={city}&appid={api_key}&units=metric"
response = requests.get(url)
data = response.json()
if data["cod"] != "404":
main = data["main"]
temperature = main["temp"]
humidity = main["humidity"]
print(f"Temperature: {temperature}°C")
print(f"Humidity: {humidity}%")
else:
print("City not found.")
Demo
• Thank you!