如何在我的Python代码中给出两种可能的结果

时间:2017-08-29 18:34:56

标签: python timer countdown

我试图在python中创建一个简单的计时器和倒计时,但是对于第一个问题,无论你键入什么,你选择计时器或倒计时,它都会给你计时器而不是倒计时。我该如何改变呢?

    import time
    def resetVar():
x = input("Timer or countdown?:")
minsum = int(input("How long do you want the timer to go?: "))
reminder = int(input("How often do we notify you in minutes?: "))
mins = 0
countminsum = 0
mins = 0
x = input("Timer or countdown?:")
if(x == "Timer" or "timer"):
    minsum = int(input("How long do you want the timer to go?: "))
    reminder = int(input("How often do we notify you in minutes?: "))
    print("Countdown has started.")
    while mins != minsum:
        time.sleep(reminder * 60)
        mins += reminder
        print(str(reminder) + " Minute(s) have passed")

    if mins == minsum:
        print("timer has ended")
        resetVar()
        print(x)
if(x == "Countdown" or "countdown"):
    countminsum = int(input("How long shout the countdown go for?: "))
    remider = int(input("How often should we notify you how much time is left? (in minutes): "))
    print ("countdown has started")
    while countminsum != mins:
            time.sleep(remider * 60)
            countminsum -= remider
            printe(str(remider) + " Minute(s) have passed.")

    if countminsum == 0:
        print ("Countdown has ended.")
        resetVar()
        print (x)

1 个答案:

答案 0 :(得分:0)

您无法检查x是计时器还是计时器,因为它的计算结果为x == 'Timer',("Timer" or "timer" == 'Timer'),而您可以说x in ['timer', 'Timer']

同样适用于倒计时。