Programm stoppt nach Eingabe [geschlossen]Python

Python-Programme
Guest
 Programm stoppt nach Eingabe [geschlossen]

Post by Guest »

Ich verwende die OpenWeather-API, um nur das aktuelle Wetter abzurufen. Mit diesem Code kann ich es dazu bringen, die Wetterdaten anzuzeigen. (formatierter API-Code ausgegeben)

Code: Select all

import requests

def current_weather():
city_name = ('Houston')
api_key = ('My api code')
url = ('http://api.openweathermap.org/data/2.5/weather?q={}&appid={}').format(city_name, api_key)
info = requests.get(url).json()
print(info);

current_weather()
Ergebnis:

Code: Select all

{
'coord': {
'lon': -95.3633,
'lat': 29.7633
},
'weather': [
{
'id': 800,
'main': 'Clear',
'description': 'clear sky',
'icon': '01d'
}
],
'base': 'stations',
'main': {
'temp': 295.42,
'feels_like': 294.72,
'temp_min': 294.14,
'temp_max': 297.09,
'pressure': 1024,
'humidity': 39
},
'visibility': 10000,
'wind': {
'speed': 2.24,
'deg': 66,
'gust': 3.58
},
'clouds': {
'all': 1
},
'dt': 1634495143,
'sys': {
'type': 2,
'id': 2006306,
'country': 'US',
'sunrise': 1634473467,
'sunset': 1634514521
},
'timezone': -18000,
'id': 4699066,
'name': 'Houston',
'cod': 200
}
[Finished in 287ms]
Aber dann versuche ich, den Stadtnamen in die Eingabe einzufügen, und er fragt mich einfach, in welcher Stadt ich bin, und stoppt das Programm.

Code: Select all

def current_weather():
city_name = input('What city are you in?: ')
api_key = ('My api code')
url = ('http://api.openweathermap.org/data/2.5/weather?q={}&appid={}').format(city_name, api_key)
info = requests.get(url).json()
print(info);

current_weather()
Ergebnis: In welcher Stadt bist du?: Paris
Und sonst nichts.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post