└── Main /Main: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | API_KEY = "your_api_key" 4 | BASE_URL = "http://api.openweathermap.org/data/2.5/weather" 5 | 6 | def get_weather(city): 7 | response = requests.get(BASE_URL, params={"q": city, "appid": API_KEY, "units": "metric"}) 8 | data = response.json() 9 | 10 | if response.status_code == 200: 11 | print(f"Weather in {city}: {data['weather'][0]['description'].capitalize()}") 12 | print(f"Temperature: {data['main']['temp']}°C") 13 | else: 14 | print("City not found!") 15 | 16 | if __name__ == "__main__": 17 | city = input("Enter city name: ") 18 | get_weather(city) 19 | --------------------------------------------------------------------------------