Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 46e81a1

Browse files
Create weatherapp.py
1 parent 2d69e69 commit 46e81a1

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

‎R.LOKESH/task5/weatherapp.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import requests
2+
import json
3+
4+
def fetch_weather_data(api_key, city):
5+
url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric"
6+
response = requests.get(url)
7+
data = response.json()
8+
return data
9+
10+
def display_weather(data):
11+
print("Current Weather Conditions:")
12+
print("---------------------------")
13+
print(f"Weather: {data['weather'][0]['description']}")
14+
print(f"Temperature: {data['main']['temp']}°C")
15+
print(f"Humidity: {data['main']['humidity']}%")
16+
print(f"Wind Speed: {data['wind']['speed']} m/s")
17+
18+
def main():
19+
api_key = "YOUR_API_KEY"
20+
city = input("Enter city name: ")
21+
weather_data = fetch_weather_data(api_key, city)
22+
if weather_data['cod'] == 200:
23+
display_weather(weather_data)
24+
else:
25+
print("Error fetching weather data. Please check your input.")
26+
27+
if __name__ == "__main__":
28+
main()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /