Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Reset timer after a certain condition

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()

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You need to parse the hello variable as int.

This seems to be working:

        if (int(hello) == var):
            print("test")
            print(gametime)
            reset()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading