randint在python中的用法_randint在学习Python的硬方法练习中的用法43

我对学习python the hard waylink to exercise中练习43的随机用法有问题。假设我在程序的所有其他部分都完全遵循Zed Shaw的代码,并且我有from random import randint,当我运行程序并在键盘上输入3位密码时,它会返回一个“BZZZZEDDD!”。代码如下: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'

假设在guess = raw_input("[keypad]> ")中运行程序时,我输入“368”。

这不应该在code = "%d%d%d" % (randint(1,9), randint(1,9), randint(1,9))的参数内,并且对于if guess ==code:来说是真的吗?相反,它像猜猜一样运行它!=代码并返回“BZZZZEDDD!”在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值