Timer for Python game

前端 未结 10 2011
伪装坚强ぢ
伪装坚强ぢ 2021-01-31 02:38

I\'m trying to create a simple game where the point is to collect as many blocks as you can in a certain amount of time, say 10 seconds. How can I get a timer to begin ticking a

10条回答
  •  天命终不由人
    2021-01-31 03:09

    1. Asks you when to stop [seconds]
    2. Adds '0' at starting [1-9]
    import time
    import sys
    
    stop = int(input('> '))
    second = 0
    print('> Stopwatch Started.')
    
    while stop > second:
        if second < 9:
            second = second + 1
            time.sleep(1)
            sys.stdout.write('\r> ' + '0' + str(second))
        else:
            second += 1
            time.sleep(1)
            sys.stdout.write('\r' + '> ' + str(second))
    
    print('\n> Stopwatch Stopped.')
    

提交回复
热议问题