我是这个网站的新手,这是我的第一篇文章。通常只需输入我需要的内容即可找到答案,但为此,我不知道如何说出问题。试着修复它,现在已经持续了大约一个小时,但不知道出了什么问题。
我的代码在下面,当我运行它时它会打印出我拥有的函数(npc和story)以及那些正确的print语句,然后停在底部,我有一个无限的while循环没有,似乎甚至没有注意到if语句(带有打印" STORYSTORYSTORY")就在那里。
这是我的代码:
while True:
print "\n You wake up in a small room, the lights are dim and the only thing you can see is a table with a few gold pieces and a glass of water."
input1 = raw_input ("What do you do?").lower()
if input1 == "take gold":
print "\n You take the gold and it's added to your inventory"
time.sleep(3)
npc("jenkins_gold")
story("part1")
loop == 2
break
if input1 == "drink water":
print "\n You reach for the water, and gulp it down."
time.sleep(3)
npc("jenkins_water")
story("part1")
loop == 2
break
if loop == 2:
print "\n Story"
print "\n STORYSTORYSTORY"
while True:
y = 1
x = y
time.sleep(1)
我让整个游戏循环运行。底部有while循环,以防万一与它有关。如果您需要我的代码中的任何其他内容,请告诉我,我应该在几分钟内回复。谢谢
答案 0 :(得分:1)
在您的第一个while
语句中:loop == 2
计算为True
(它是一个布尔表达式,因为您使用了==
)并且没有做任何其他事情,您想要使用loop
影响2
,因此您需要执行loop = 2
(这将是一项任务,因为您将使用=
)。
while True:
print "\n You wake up in a small room, the lights are dim and the only thing you can see is a table with a few gold pieces and a glass of water."
input1 = raw_input ("What do you do?").lower()
if input1 == "take gold":
print "\n You take the gold and it's added to your inventory"
time.sleep(3)
npc("jenkins_gold")
story("part1")
loop = 2
break
if input1 == "drink water":
print "\n You reach for the water, and gulp it down."
time.sleep(3)
npc("jenkins_water")
story("part1")
loop = 2
break
答案 1 :(得分:1)
您尝试通过等号运算符loop
将{2}分配给==
。相反,使用赋值运算符=
分配它,如下所示:
loop = 2