Skip to content

Commit 66b43b3

Browse files
authored
Merge pull request csubhasundar#166 from ProgrammerDG/patch-2
Create weatherAppPython
2 parents abd59b9 + 23682c6 commit 66b43b3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

weatherAppPython

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import requests
2+
3+
api_key = "your_api_key"
4+
city = input("Enter the city name: ")
5+
6+
url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}"
7+
response = requests.get(url)
8+
data = response.json()
9+
10+
if data["cod"] == 200:
11+
weather = data["weather"][0]["description"]
12+
temperature = data["main"]["temp"]
13+
print(f"Weather in {city}: {weather}")
14+
print(f"Temperature: {temperature}°C")
15+
else:
16+
print("City not found.")

0 commit comments

Comments
 (0)