0

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.

GTAirpline
  • 65
  • 11
  • Is this for a real, actual bomb? If so, you might want want to get a more experienced coder that can make an error-tolerant code... to avoid any accidents... I'd say a bomb controller is probably too mission-critical for a first-time coding project. – SethMMorton Jun 30 '15 at 05:31
  • Absolutely not. lol. I'm planning to get a Raspberry Pi to make a CS:GO airsoft prop. Thats it :) – GTAirpline Jun 30 '15 at 20:20

2 Answers2

1

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!

Jesse
  • 11
  • 3
  • It does work, but not in the way I want it too. I want it to print how many seconds left, and tell me to enter the code, without stopping the timer. This way, it stops it – GTAirpline Jun 30 '15 at 05:24
  • Wait, what exactly do you want it to do? I assumed you were just trying to fix the exception it throws. – Jesse Jun 30 '15 at 05:25
  • 1
    I think I figured out what you want. You want it to continually count down until you enter the code. [This](http://stackoverflow.com/questions/2933399/how-to-set-time-limit-on-input) might help. – Jesse Jun 30 '15 at 05:30
0

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)
Alex Ivanov
  • 695
  • 4
  • 6