最后两个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
答案 0 :(得分:0)
此处只能执行一个elif
语句。满足条件的第一个将是执行的 - 其余的被忽略。
“left”将始终处于“硬左”状态,无论如何。与“硬权利”相同。因此,底部的2 elif
语句将永远不会被执行。