GTAirpline
GTAirpline

Reputation: 65

Stopping a timer with a specific code

I'm trying to make a Bomb timer than can be stopped at any given moment using a specific code. which is 7355608

I've tried doing this but I fail at it, also please keep in mind I'm relatively new to python.

Also, thanks in advance.

import time

def countdown():
    for n in range(45, 0, -1):
        print n
        time.sleep(1)
        code = int(raw_input("Enter code:"))
        if code == passcode:
            break
countdown()
passcode = 7355608

P.S: I know the code is really bad, because I'm new to python.

Upvotes: 0

Views: 1048

Answers (2)

Alex Ivanov
Alex Ivanov

Reputation: 823

I think you should do like this:

def countdown(passcode):
    for n in range(45, 0, -1):
        print n
        time.sleep(1)
        code = int(raw_input("Enter code:"))
        if code == passcode:
            break
countdown(7355608)

Upvotes: 0

Jesse
Jesse

Reputation: 11

You need to tell the program what "passcode" is before the countdown() method definition, or else python doesn't know what "passcode" means. Just move the statement "passcode = 7355608" to above the method block and it should work!

Upvotes: 1

Related Questions