我是一名新的计算机老师,我在使用此代码时遇到了一些问题。我试图让我的学生用while和if语句创建一个非常简单的游戏。用户输入无法存储在变量中
当我运行这段代码时,它不会接受我输入的y或n,它会一直出现错误。任何想法为什么?
monsterHealth = 20
playerHealth = 50
while monsterHealth > 0:
print ("The monster attacks you dealing 10 damage")
global playerHealth
playerHealth = playerHealth - 10
playerDecision = input("Would you like to stay and fight? y/n")
if playerDecision == y:
print ("You attack the monster and do 5 damage")
if playerDecision == n:
print("You run away with your tail between your legs.")
break
if playerHealth <= 0:
print ("You died......")
break
if monsterHealth <= 0:
print ("You defeated the monster!")
break
我希望有更多的从一台计算机老师..请..“Y”,“N” .. – Maroun
请修复代码的格式。也请修复明显的错误。我希望计算机老师能够做到这一点。 – skyking
你应该阅读你收到的错误,它会告诉你什么是错的。如果你真的不能解决它,*在这里发布错误*,我们将解释它。 –