Question
I NEED SOMEONE TO CRIQUTIC ME. THIS IS WHAT I NEED: Create a Python Application which asks the user for their zip code or city.
I NEED SOMEONE TO CRIQUTIC ME. THIS IS WHAT I NEED:
Create a Python Application which asks the user for their zip code or city.
Use the zip code or city name in order to obtain weather forecast data from: http://openweathermap.org/
Display the weather forecast in a readable format to the user.
Use comments within the application, where appropriate, in order to document what the program is doing.
Use functions including a main function.
Allow the user to run the program multiple times.
Validate whether the user entered valid data. If valid data isnt presented, notify the user.
Use the Requests library in order to request data from the webservice.
Use try blocks when establishing connections to the webservice. You must print a message to the user indicating whether or not the connection was successful.
THIS IS WHAT I HAVE:
import requests
def main(): # Ask the user for their zip code or city location = input("Please enter your zip code or city: ") # Use the zip code or city name to obtain weather forecast data from openweathermap.org try: api_key = "MY_API_KEY" url = f"http://api.openweathermap.org/data/2.5/weather?q={location}&appid={api_key}" response = requests.get(url) # Validate whether the user entered valid data if response.status_code != 200: print("Invalid location. Please try again.") return # Display the weather forecast in a readable format to the user data = response.json() print("Weather forecast for", data["name"] + ":") print("Temperature:", data["main"]["temp"], "degrees Fahrenheit") print("Humidity:", data["main"]["humidity"], "%") print("Description:", data["weather"][0]["description"]) except requests.exceptions.RequestException as e: # Print a message to the user indicating whether or not the connection was successful print("Error: Unable to establish connection to the webservice.")
if __name__ == "__main__": while True: main() # Allow the user to run the program multiple times run_again = input("Do you want to run the program again? (y/n) ") if run_again.lower() != "y": break
AM I MISSING ANYTHING PLEASE HELP DUE SATURDAY
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started