Assignment Title: Weather Report Using Python
Objective:
The purpose of this assignment is to create a Python program that fetches and
displays real-time weather data for a user-specified city using the OpenWeatherMap
API.
Tools & Technologies Used:
- Programming Language: Python
- API Used: OpenWeatherMap
- Library: requests (for handling HTTP requests)
Program Overview:
This program asks the user to input a city name. It then connects to the
OpenWeatherMap API and retrieves the current weather data for that city. The data
includes:
- City and Country
- Temperature and Feels Like Temperature
- Weather Description (e.g., Clear sky, Rainy)
- Humidity Level
The results are printed in a user-friendly format with relevant icons and messages.
Key Features:
- Real-time weather updates
- User input-based city selection
- Error handling for invalid city names or API issues
- Output in human-readable and clean format
Code Explanation:
- The function get_weather(city) takes a city name as input.
- It sends a request to the OpenWeatherMap API using the provided API key.
- The JSON response is parsed to extract necessary weather details.
- A formatted weather report is printed.
- The program includes a try-except block for handling any unexpected errors.
Conclusion:
This program is a practical example of how Python can be used to work with web APIs
and display real-time data. It enhances understanding of HTTP requests, JSON
parsing, and user interaction via console.