We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e55477a commit b5287dbCopy full SHA for b5287db
weather-app.py
@@ -17,9 +17,17 @@ def get_temperature(city_name, api_key):
17
return None
18
19
def main():
20
- api_key = "YOUR_API_KEY_HERE" # Replace this with your OpenWeatherMap API key
+ import os
21
+ api_key = os.getenv('OPENWEATHER_API_KEY')
22
+ if not api_key:
23
+ print("Error: Please set the OPENWEATHER_API_KEY environment variable")
24
+ return
25
+
26
city = input("Enter a major U.S. city: ").strip()
-
27
+ if not city:
28
+ print("Error: City name cannot be empty")
29
30
31
temp = get_temperature(city, api_key)
32
if temp is not None:
33
print(f"The current temperature in {city.title()} is {temp:.1f}°F.")
0 commit comments