Nå fungerer det endelig!
Takk for alle svar, KP gitt
Kode
# - Good Morning Program -
#Import
import datetime
import requests
import sys
#Input
name_of_user = input("What is your name?: ")
#Loop
while True:
#Input
city = input('City Name: ')
# API
api_address='http://api.openweathermap.org/data/2.5/weather?appid=0c42f7f6b53b244c78a418f4f181282a&q='
url = api_address + city
json_data = requests.get(url).json()
# Variables
format_add = json_data['main']['temp']
day_of_month = str(datetime.date.today().strftime("%d "))
month = datetime.date.today().strftime("%b ")
year = str(datetime.date.today().strftime("%Y "))
time = str(datetime.datetime.now().strftime("%H:%M:%S"))
degrees = format_add - 273.15
humidity = json_data['main']['humidity']
latitude = json_data['coord']['lon']
longitude = json_data['coord']['lat']
#Program
if degrees < 20 and time > str(12.00):
print("\nGood afternoon " + name_of_user + ".")
print("\nThe date today is: " +
day_of_month +
month +
year)
print("The current time is: " + time)
print("The humidity is: " + str(humidity) + '%')
print("Latitude and longitude for " + city + " is: " + str(latitude), str(longitude))
print("The temperature is a mild " + "{:.1f}".format(degrees) +
"°C, you might need a jacket.")
elif degrees < 20 and time < str(12.00):
print("\nGood morning " + name_of_user + ".")
print("\nThe date today is: " +
day_of_month +
month +
year)
print("The current time is: " + time)
print("The humidity is: " + str(humidity) + '%')
print("Latitude and longitude for " + city + " is: " + str(latitude), str(longitude))
print("The temperature is a mild " + "{:.1f}".format(degrees) +
"°C, you might need a jacket.")
elif degrees >= 20 and time > str(12.00):
print("\nGood afternoon " + name_of_user + ".")
print("\nThe date today is: " +
day_of_month +
month +
year)
print("The current time is: " + time)
print("The humidity is: " + str(humidity) + '%')
print("Latitude and longitude for " + city + " is: " + str(latitude), str(longitude))
print("The temperature is a warm " + "{:.1f}".format(degrees) +
"°C, don't forget to drink water.")
elif degrees >= 20 and time < str(12.00):
print("\nGood morning " + name_of_user + ".")
print("\nThe date today is: " +
day_of_month +
month +
year)
print("The current time is: " + time)
print("The humidity is: " + str(humidity) + '%')
print("Latitude and longitude for " + city + " is: " + str(latitude), str(longitude))
print("The temperature is a warm " + "{:.1f}".format(degrees) +
"°C, don't forget to drink water.")
restart = input('Would you like to check another city (y/n)?: ')
if restart == 'y':
continue
else:
print('Goodbye')
sys.exit()
Ser sånn her ut:
What is your name?: Hvagjordo
City Name: Stavanger
Good afternoon Hvagjordo.
The date today is: 01 May 2019
The current time is: 22:14:56
The humidity is: 93%
Latitude and longitude for Stavanger is: 5.73 58.97
The temperature is a mild 7.2°C, you might need a jacket.
Would you like to check another city (y/n)?: y
City Name: Oslo
Good afternoon Hvagjordo.
The date today is: 01 May 2019
The current time is: 22:15:00
The humidity is: 87%
Latitude and longitude for Oslo is: 10.74 59.91
The temperature is a mild 10.7°C, you might need a jacket.
Would you like to check another city (y/n)?: y
City Name: Svinesund
Good afternoon Hvagjordo.
The date today is: 01 May 2019
The current time is: 22:16:16
The humidity is: 47%
Latitude and longitude for Svinesund is: 11.27 59.1
The temperature is a mild 12.2°C, you might need a jacket.
Would you like to check another city (y/n)?: n
Goodbye
Process finished with exit code 0