最后两个elif语句不起作用;它只是将我重定向到前两个。对于else语句,它不会打印点数。为什么这个代码不起作用?谢谢
def match_duel():
print "do you want to swing right or left"
print "and for how many points?"
choice = raw_input("> ")
points = 0
damage = 0
if "right" in choice:
print "you take a swing right. 20 points."
points = points + 20
print "You have %d points" % points
match_duel()
elif "left" in choice:
print "you take a swing left. 50 points."
points = points + 50
print "You have %d points" % points
match_duel()
elif "hard right" in choice:
print "you take a hard swing right for 100 points."
print "cthulhu strikes back with 100 points."
print "you take half the damage."
points = points + 100
damage = damage - 50
print "You have %d points" % points
print "You have %d damage" % damage
match_duel()
elif "hard left" in choice:
print "you take a hard swing left for 200 points."
print "cthulhu strikes back with 50 points, taken by surprise."
print "you take half the damage"
points = points + 200
damage = damage - 25
print "You have %d points" % points
print "You have %d damage" % damage
match_duel()
else:
print "take an extended hit."
points = points + 300
print "You have %d points" % points
这里只能执行一个
elif
语句。满足条件的第一个将被执行,其余的将被忽略不管怎样,“左”总是在“硬左”中。与“右倾”相同。因此,底部的2
elif
语句将永远不会执行相关问题 更多 >
编程相关推荐