import requests

# Replace with your OpenWeatherMap API key
API_KEY = "YOUR_API_KEY"
BASE_URL = "https://api.openweathermap.org/data/2.5/weather"

def get_weather_data(location):
  """Fetches weather data for a given location."""
  url = f"{BASE_URL}?q={location}&appid={API_KEY}"
  response = requests.get(url)

  if response.status_code == 200:
    return response.json()
  else:
    print(f"Error: {response.status_code}. Failed to retrieve weather data.")
    return None

def display_weather(data):
  """Displays weather information in a user-friendly format."""
  if data is None:
    return

  city = data["name"]
  temp_kelvin = data["main"]["temp"]
  humidity = data["main"]["humidity"]
  wind_speed = data["wind"]["speed"]

  # Convert Kelvin to Celsius
  temp_celsius = round(temp_kelvin - 273.15, 2)

  print(f"Weather in {city}:")
  print(f"  Temperature: {temp_celsius}°C")
  print(f"  Humidity: {humidity}%")
  print(f"  Wind Speed: {wind_speed} m/s")

def main():
  # Get user input for location
  location = input("Enter city name or zip code: ")

  # Fetch and display weather data
  weather_data = get_weather_data(location)
  display_weather(weather_data)

if __name__ == "__main__":
  main()
