代码未返回预期结果

时间:2018-05-07 02:18:54

标签: python

我试图制作一个小小的文字冒险游戏。

为什么这句话不会返回90?

orc = raw_input("Does the orc attack or miss?")#Replacing with a random number thing later
health = 100

takeahit = 0

def damage(orc):
  if orc == "hit":
    return takeahit == 10 # Ive tried plus as well im having similar problems with choices in inventory
  elif orc == "miss":
    print "The Orc misses"

healthtwo = health - takeahit

print healthtwo

1 个答案:

答案 0 :(得分:1)

以适当的方式从函数返回:

gatsby-browser.js

您需要调用定义的函数。 在函数定义

之后添加它
def damage(orc):
    print(orc)
    if orc == "hit":
        takeahit = 10 #MODIFIED
    elif orc == "miss":
        takeahit=0
        print "The Orc misses"
    return takeahit  #ADDED STATEMENT