|
- class LaserWeaponArmory(Scene):
- def enter(self):
- print "You do a dive roll into the Weapon Armory, crouch and scan the room"
- print "for more Gothons that might be hiding. It's dead quiet, too quiet."
- print "You stand up and run to the far side of the room and find the"
- print "neutron bomb in its container. There's a keypad lock on the box"
- print "and you need the code to get the bomb out. If you get the code"
- print "wrong 10 times then the lock closes forever and you can't"
- print "get the bomb. The code is 3 digits."
- code = "%d%d%d" % (randint(1,9), randint(1,9), randint(1,9))
- guess = raw_input("[keypad]> ")
- guesses = 0
- while guess != code and guesses < 10:
- print "BZZZZEDDD!"
- guesses += 1
- guess = raw_input("[keypad]> ")
- if guess == code:
- print "The container clicks open and the seal breaks, letting gas out."
- print "You grab the neutron bomb and run as fast as you can to the"
- print "bridge where you must place it in the right spot."
- return 'the_bridge'
- else:
- print "The lock buzzes one last time and then you hear a sickening"
- print "melting sound as the mechanism is fused together."
- print "You decide to sit there, and finally the Gothons blow up the"
- print "ship from their ship and you die."
- return 'death'
复制代码
1. 这个输密码的要猜11次。而且无论是修改guesses的初始值为大于0的数,或是修改循环的条件,只要 guess != code都是猜11次
- def enter(self):
- print "You do a dive roll into the Weapon Armory, crouch and scan the room"
- print "for more Gothons that might be hiding. It's dead quiet, too quiet."
- print "You stand up and run to the far side of the room and find the"
- print "neutron bomb in its container. There's a keypad lock on the box"
- print "and you need the code to get the bomb out. If you get the code"
- print "wrong 10 times then the lock closes forever and you can't"
- print "get the bomb. The code is 3 digits."
- code = "%d%d%d" % (randint(1,9), randint(1,9), randint(1,9))
- print code #**************
- guess = raw_input("[keypad]> ")
- guesses = 0
复制代码
2. 三位随机数很难猜中,我想在脚本中打印出密码。为什么在code = "%d%d%d" % (randint(1,9), randint(1,9), randint(1,9))下一行用print code输出字符串,运行时会显示IndentationError: unexpected indent |
|