This project fetches real-time weather data from the internet (using the OpenWeatherMap API). You type a city, and it shows the current temperature and conditions.
- Using APIs (connecting your program to online services).
- Sending HTTP requests with the
requests
library. - Handling JSON data in Python.
This teaches you how Python interacts with the web.
import requests
city = input("Enter city name: ")
api_key = "your_api_key_here" # get free key from openweathermap.org
url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric"
response = requests.get(url).json()
print(f"Weather in {city}: {response['main']['temp']}°C, {response['weather'][0]['description']}")