Question: Develop a Python program that simulates a weather forecasting service . The program should allow users to perform the following operations: Set Location: Users can

Develop a Python program that simulates a weather forecasting service. The program should allow users to perform the following operations:

  1. Set Location: Users can set their current location by providing city and country names.
  2. Get Weather Forecast: Users can retrieve a weather forecast for the next 7 days, including temperature, precipitation, and wind speed.
  3. Change Units: Users can change the units of measurement for temperature (Celsius or Fahrenheit) and wind speed (km/h or mph).
  4. Save Forecast: Users can save the forecast details to a file for later reference.
  5. Display Forecast: Display the weather forecast in a user-friendly format.

Requirements:

  • Use functions and data structures to organize the weather data.
  • Implement error handling for cases such as invalid locations or unsupported units.
  • Simulate fetching weather data from an API (you can use hardcoded data for the purpose of this exercise).

Sample Code Structure:

class WeatherService:
    def __init__(self):
        # Your code here

    def set_location(self, city, country):
        # Your code here

    def get_weather_forecast(self):
        # Your code here

    def change_units(self, temperature_unit, wind_speed_unit):
        # Your code here

    def save_forecast(self, filename):
        # Your code here

    def display_forecast(self):
        # Your code here

# Example usage:
weather_service = WeatherService()
weather_service.set_location("Tokyo", "Japan")
weather_service.get_weather_forecast()
weather_service.change_units("Celsius", "km/h")
weather_service.display_forecast()

 


Step by Step Solution

3.44 Rating (160 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Heres a Python program that simulates a weather forecasting service with the requested features python class WeatherService def initself selflocation ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!