How to make a timer program in Python

前端 未结 11 2454
予麋鹿
予麋鹿 2021-02-08 14:24

Here is my goal: To make a small program (text based) that will start with a greeting, print out a timer for how long it has been since the last event, and then a timer for the

11条回答
  •  没有蜡笔的小新
    2021-02-08 15:23

    This is my version. It's great for beginners.

         # Timer
    import time
    print("This is the timer")
    # Ask to Begin
    start = input("Would you like to begin Timing? (y/n): ")
    if start == "y":
        timeLoop = True
    
    # Variables to keep track and display
    Sec = 0
    Min = 0
    # Begin Process
    timeLoop = start
    while timeLoop:
        Sec += 1
        print(str(Min) + " Mins " + str(Sec) + " Sec ")
        time.sleep(1)
        if Sec == 60:
            Sec = 0
            Min += 1
            print(str(Min) + " Minute")
    # Program will cancel when user presses X button
    

提交回复
热议问题