【发布时间】:2019-09-21 08:21:18
【问题描述】:
我正在制作一个基于文本的小游戏来练习我的 Python 技能。我正在努力让 if 语句根据我的用户输入显示正确的结果。
weapon_choice = str(input("You can choose between three weapons to defeat the beast!"
" Press 1 for Axe, 2 for Crossbow, 3 for Sword."))
if input(1):
print("You chose the Axe of Might")
elif input(2):
print("You chose the Sacred Crossbow")
else:
print("You chose the Elven Sword")
我希望输出会询问我一个数字(1、2 或 3),然后打印与该数字关联的字符串。相反,当我输入 1 时,它会打印 1,然后是 2,然后是与数字 3 关联的字符串('else' 选项),无论我输入什么数字。我不明白为什么?
Greetings, weary wanderer.
Welcome to Freyjaberg. Choose your weapon.
You can choose between three weapons to defeat the beast! Press 1 for Axe, 2 for Crossbow, 3 for Sword.1
1
2
You chose the Elven Sword
Process finished with exit code 0
【问题讨论】:
-
除了用
1提示用户之外,您还期望if input(1)做什么?
标签: python if-statement input