I suspect that all the places you have
That what you really want is self.break_out()
-
from random import randint
-
-
class firstRoom():
-
def __init__(self):
-
print "Welcome to the start of the game. Good luck finishing it."
-
print "There is a keypad on the door. You have to get all 3 digits correct, or the door will never open again."
-
-
self.break_out()
-
-
def break_out(self):
-
-
# Until everythin is working only one number
-
combination = "%d" % (randint(1,3))
-
guesses = 0
-
guess = raw_input("[KEYPAD]>")
-
-
-
while guess != combination and guesses < 10:
-
print "INCORRECT, TRY AGAIN"
-
guesses += 1
-
print combination, guesses # Debug added by me
-
self.break_out()
-
-
if guess == combination:
-
print "welldone"
-
-
-
if __name__ == "__main__":
-
firstRoom()
-
And if so you have an other major problem in your code. Every time you guess the combination resets as well as guesses.
edit. I got bored and fixed the program up a bit as well as extending it to make the guessing a bit more fair.
- from random import randint
-
-
class firstRoom():
-
-
def __init__(self):
-
-
print "Welcome to the start of the game. Good luck finishing it."
-
print """There is a keypad on the door. You have to get all 3 digits
-
correct, or the door will never open again."""
-
-
# Until everythin is working only one number
-
self.combination = "".join([str(randint(0,9)) for x in xrange(3)])
-
self.guesses = 0
-
-
def break_out(self):
-
-
guess = raw_input("[KEYPAD]>")
-
-
if guess != self.combination and self.guesses < 10:
-
-
print "INCORRECT, TRY AGAIN"
-
self.guesses += 1
-
self.eval_guess(guess)
-
self.break_out()
-
-
elif guess == self.combination:
-
print "welldone"
-
-
else:
-
print "FAIL!"
-
-
def eval_guess(self, guess):
-
-
# print self.guesses, self.combination # Debug
-
-
if len(guess) == 3 and guess.isdigit():
-
lg = []
-
for x, y in zip(guess, self.combination):
-
if int(x) < int(y):
-
lg.append("<")
-
-
elif int(x) > int(y):
-
lg.append(">")
-
-
else:
-
lg.append("=")
-
-
print "".join(lg)
-
-
-
if __name__ == "__main__":
-
x = firstRoom()
-
x.break_out()