Cobra_Pro

🌦️ Introduction

The current image has no alternative text. The file name is: KIN.jpg

In this project, you’ll build a Weather App in Python that retrieves live weather information from an online API.
You’ll learn how to work with HTTP requests, JSON data, and API keys — essential skills for modern developers.


🧠 Key Concepts Covered

ConceptDescription
APIsApplication Programming Interfaces — services that let your code talk to other systems.
Requests ModuleA Python library used to send HTTP requests and receive data.
JSON ParsingConverting JSON data into Python dictionaries for easy handling.

🧰 What You’ll Need

  • Python 3 installed
  • requests library (install with pip install requests)
  • Free API key from OpenWeatherMap

💻 Step-by-Step Code

File Name: weather_app.py

import requests

# 🔑 Replace with your own API key
API_KEY = "your_api_key_here"
BASE_URL = "https://api.openweathermap.org/data/2.5/weather"

print("🌤️ Welcome to the Python Weather App!")

city = input("🏙️ Enter city name: ")

# Build full URL with parameters
params = {
    "q": city,
    "appid": API_KEY,
    "units": "metric"
}

response = requests.get(BASE_URL, params=params)

if response.status_code == 200:
    data = response.json()
    main = data["main"]
    weather = data["weather"][0]
    
    print(f"\n📍 City: {data['name']}")
    print(f"🌡️ Temperature: {main['temp']}°C")
    print(f"💧 Humidity: {main['humidity']}%")
    print(f"☁️ Condition: {weather['description'].title()}")
else:
    print("⚠️ City not found or API error.")

🧩 Example Output

🌤️ Welcome to the Python Weather App!
🏙️ Enter city name: London

📍 City: London
🌡️ Temperature: 17.5°C
💧 Humidity: 62%
☁️ Condition: Light Rain

🧠 How It Works
  1. The user inputs a city name.
  2. Python sends a GET request to the OpenWeatherMap API.
  3. The app retrieves the JSON response, which includes temperature, humidity, and condition.
  4. It then displays the data neatly in the console.

⚙️ Improvements You Can Add
  • Convert temperature between Celsius and Fahrenheit.
  • Display wind speed and pressure.
  • Build a GUI version using tkinter.
  • Create a daily forecast version with extended API endpoints.

📝 Summary
  • You learned how to interact with an external API using Python.
  • You practiced JSON parsing and error handling.
  • You built a real-time Weather App ready for future improvements.
⬇️ Download cobra_king تحميل Server 1

Related Posts

NetCinFly

📘 Introduction In this project, you’ll develop a Student Grades Analyzer in Python that can: This project helps you strengthen your skills with lists, dictionaries, loops, and data analysis logic….

Read more

Eagle_Pro

🌐 Introduction In this project, you’ll create a Web Scraper App in Python that extracts quotes, authors, and tags from a live website.You’ll use the BeautifulSoup and Requests libraries to…

Read more

Show7-Pro

Concepts Covered: 🎯 Objective: Create a simple, text-based contact book application that allows users to: 💡 Code (contact_book.py): 🧠 Example Usage Console Output Example: 💾 Notes ⬇️ Download Show7-Pro تحميل…

Read more

Rapid_tv

🔹 Introduction The Rock, Paper, Scissors Game is a classic hand game that you can easily build in Python. 👉 Rules: 🔹 Code Example 🔹 Example Run 🔹 Concepts Learned…

Read more

VOD-ZalHD

🔹 Introduction The Number Guessing Game is a classic beginner Python project. 🔹 Code Example 🔹 Example Run 🔹 Concepts Learned 🔹 Summary ⬇️ Download VOD-ZalHD تحميل Server 1 ⬇️…

Read more

Delux_pro

🔹 Introduction The To-Do List App is one of the most popular beginner projects. It teaches you how to: 🔹 Code Example 🔹 Features of This App 🔹 Example Run…

Read more