# Importing requests library to make HTTP requests
import requests  

def get_weather(city_name):
    # Replace with your actual API key
    api_key = "2a9ebaba4d80bc82ab75db55eeaf294d"  
    base_url = "http://api.openweathermap.org/data/2.5/weather"
    
    # Setting up parameters to be passed to the API
    params = {
        "q": city_name,
        "appid": api_key,
        # Celsius; for Fahrenheit, use "imperial"
        "units": "metric"  
    }
    
    # Making a GET request to the API
    response = requests.get(base_url, params=params)
    
    # Checking if the request was successful (status code 200)
    if response.status_code == 200:
        # Converting the response JSON to a dictionary
        data = response.json()
        
        # Extracting useful information
        temperature = data["main"]["temp"]
        weather_description = data["weather"][0]["description"]
        
        # Displaying the weather information
        print(f"The temperature in {city_name} is {temperature}°C with {weather_description}.")
    else:
        print("City not found or invalid API key.")

# Testing the function
get_weather("Swansea")
