1

Im revisiting this tutorial of classes from LPTHW:

http://learnpythonthehardway.org/book/ex43.html

Im in the middle of the 'class LaserWeaponArmory(Scene)' and playing around with the while loop for the code guess and I tried doing it a bit different like this:

    code = randint(1,3)
    user_guess = raw_input("> ")        

    while user_guess != code:
        print "BZZZT!"
        print "Try again"
        user_guess = raw_input("> ")

    if user_guess == code:

        print "The door slides open and you grab the bomb"
        return 'the_bridge'
    else:
        print "The lock buzzes again and the Gothons charge in anc kill you"
        return 'death'

However this just seems to loop endlessly for me and I never get the right answer.

If I change the first line to this:

code = "%d" % randint(1,3)

it works just fine, but if I open the Python terminal and do the following:

x = randint(1,3)

x will then return a random int between 1 and 3 which is exactly what I was trying to make the program do but it didn't seem to work as I expected.

Im confused about why "%d" % is required in the program for it to work.

easy_c0mpany80
  • 327
  • 1
  • 7
  • 18

0 Answers0