View Single Post
Trådstarter
199
Sitat av Myoxocephalus Vis innlegg

Kode

import sys #settes sammen med dine øvrige imports
sys.exit() # settes hvor du vil avslutte programmet
Vis hele sitatet...

Sånn som det her ikke sant?

Kode

# - Good Morning Program -

#Import
import datetime
import requests
import sys

#Input
name_of_user = input("What is your name?: ")
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']

#Loop
while True:

    #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.")

#Loop
while True:
    restart = input('Would you like to check another city (y/n) ?: ')
    if restart == 'y':
        break
    else:
        print('Goodbye')
        sys.exit()
Da får jeg dette som looper i det uendelige uten at jeg trykker y eller n fremdeles :


What is your name?: Hvagjordo
City Name: Oslo

Good afternoon Hvagjordo.

The date today is: 01 May 2019
The current time is: 17:13:16
The humidity is: 47%
Latitude and longitude for Oslo is: 10.74 59.91
The temperature is a mild 15.9°C, you might need a jacket.

Good afternoon Hvagjordo.

The date today is: 01 May 2019
The current time is: 17:13:16
The humidity is: 47%
Latitude and longitude for Oslo is: 10.74 59.91
The temperature is a mild 15.9°C, you might need a jacket.

Good afternoon Hvagjordo.

The date today is: 01 May 2019
The current time is: 17:13:16
The humidity is: 47%
Latitude and longitude for Oslo is: 10.74 59.91
The temperature is a mild 15.9°C, you might need a jacket.