can you fix this code so is not hardcoded, and also make it user interaction so the user can input any city or state and get live weather data   import requests import pandas as pd # Set API endpoint and parameters url = "http://api.openweathermap.org/data/2.5/weather" params = {     "lat": 41.85,     "lon": -87.65,     "appid":"bdc131976a43a5df7074f0aef35fc088",     "units": "imperial" } # Make GET request to API response = requests.get(url, params=params) # Check if request was successful if response.status_code == 200:     # Parse JSON data from response     data = response.json()         # Extract relevant information from data     location = data['name']     temp = data['main']['temp']     humidity = data['main']['humidity']     description = data['weather'][0]['description']         # Print weather information     print(f"Current weather in {location}:")     print(f"Temperature: {temp}°F")     print(f"Humidity: {humidity}%")     print(f"Description: {description}") else:     print("Error retrieving weather information")

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter14: Files And Streams
Section: Chapter Questions
Problem 2CP: In Chapter 11, you created the most recent version of the MarshallsRevenue program, which prompts...
icon
Related questions
Question
100%

can you fix this code so is not hardcoded, and also make it user interaction so the user can input any city or state and get live weather data

 

import requests
import pandas as pd

# Set API endpoint and parameters
url = "http://api.openweathermap.org/data/2.5/weather"
params = {
    "lat": 41.85,
    "lon": -87.65,
    "appid":"bdc131976a43a5df7074f0aef35fc088",
    "units": "imperial"
}

# Make GET request to API
response = requests.get(url, params=params)

# Check if request was successful
if response.status_code == 200:
    # Parse JSON data from response
    data = response.json()
   
    # Extract relevant information from data
    location = data['name']
    temp = data['main']['temp']
    humidity = data['main']['humidity']
    description = data['weather'][0]['description']
   
    # Print weather information
    print(f"Current weather in {location}:")
    print(f"Temperature: {temp}°F")
    print(f"Humidity: {humidity}%")
    print(f"Description: {description}")
else:
    print("Error retrieving weather information")

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

what compiler did you use

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Files and Directory
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage