Okax so I started learniny Python for a week and i wanted to write a code that displays a clock. So this is it. Everything is fine but it wont switch from 24 to 0 / 12 to 0 and i don't get why. Do you have any tipps for a better style? [time.localtime] i've found too late :D [im not finished yet] (sorry for not pleasing you with my english)
from time import sleep
def wrong_input():
global formt
formt = input("Do you want to use the 24-Hours format?\nFor yes type Y, for no type N\n")
if not (formt == "N" or formt == "n" or formt == "Y" or formt == "y"):
print("ERROR, wrong input")
wrong_input()
wrong_input()
def too_high():
global hr
hr = int(input("Please enter the Hours:\n"))
if (formt == "N" or formt == "n") and hr > 12:
print("ERROR")
too_high()
too_high()
min = int(input("Please enter the Minutes:\n"))
sec = int(input("Please enter the Secondes:\n"))
while True:
print(hr, ":", min, ":", sec)
sec += 1
sleep(1)
if (sec >= 60):
min += 1
sec = 0
if (min >= 60):
hr += 1
min = 0
if (12 <= hr and formt == "N"):
hr = 1
if (23 <= hr and formt == "Y"):
hr = 0
Aucun commentaire:
Enregistrer un commentaire