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
解决方案
以适当的方式从函数返回:
def damage(orc):
print(orc)
if orc == "hit":
takeahit = 10 #MODIFIED
elif orc == "miss":
takeahit=0
print "The Orc misses"
return takeahit #ADDED STATEMENT
您需要调用定义的函数。在函数定义后添加
takeahit=damage(orc)
推荐阅读
- ios - Fabric 没有向我的仪表板发送数据
- unity3d - Unity - GetKeyDown 和 GetKey 使用相同的 KeyCode 来获得输入延迟(如果按住)
- ios - 在 iOS 中使用相机时获取运动传感器数据
- ssl - 如何使用 Jenkins Artifactory 插件避免柯南 SSL 用户身份验证错误?
- java - java.io.IOException: COSStream 已关闭,无法读取。也许其封闭的 PDDocument 已关闭?
- c# - Dijkstra 算法:如果有 2 个图未连接,它应该工作吗?
- javascript - 使用 Flow 验证对象映射
- ios - “因特征而异”的错误
- swift - 如何以编程方式在 Firebase 中创建动态链接?迅速
- pandas - 使用统计模型和 matplotlib 绘制线性方程