Reset timer after a certain condition

Question:

The while loop in the game() only runs for 10 sec. I want to reset the time (run the while loop for 10 sec again). when certain conditions are meet. The code below is not even executing the if condition.

import time
gametime = time.time()+ 10
def game(): 
    print("Seconds since epoch =", gametime)    
    var = 1
    while time.time() < gametime:
        print ("hello")
        hello = input("reset time: ")
        print("test1")
        if (hello == var):
            print("test")
            print(gametime)
            reset()

    print("time is up")


def reset():
    global gametime
    gametime = time.time()+ 10

game()
Asked By: Prasanna kadel

||

Answers:

You need to parse the hello variable as int.

This seems to be working:

        if (int(hello) == var):
            print("test")
            print(gametime)
            reset()
Answered By: Tamas K
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.