【发布时间】:2013-06-14 05:18:55
【问题描述】:
好的,所以我正在尝试设置一个布尔值,以便如果一个项目被取走,它变成 True,下一次如果它是 True,那么它会采用不同的路径,这是我第一次用 Python 写东西,所以请原谅糟糕的代码公约。无论如何,在记笔记之前,我需要布尔为 False,当它是时,我希望它变为 True。我将来可能会遇到的一个问题是,有一部分玩家回到了这个房间,当他们回到这个房间时,我怎样才能让 bool 保持 True?
def first_room(Note):
choice1_1 = raw_input('The house looks much larger than it did from the outside. You appear in a room, to your left is a closet, to your right is a pile of junk, in front of you is a door, and behind you is the exit.')
choice1_1 = choice1_1.lower()
if choice1_1 == 'left' or choice1_1 == 'l' or choice1_1 == 'closet':
if note == False:
choice1_c = raw_input('You open the closet and check inside, there is a note. Do you take the note? (Y/N)')
choice1_c = choice1_c.lower()
if choice1_c == 'y':
print 'You took the note.'
first_room(True)
if choice1_c == 'n':
print 'You leave the note alone.'
first_room(False)
else:
print 'The closet is empty.'
first_room(True)
first_room(False)
【问题讨论】:
-
Python 中的大小写很重要。
def first_room(Note)和def first_room(note)不是一回事。 -
您似乎正在尝试将函数调用用作 GOTO 的。这是一个坏主意,因为它不会按照您想要/期望的方式工作。
-
欢迎来到 Stack Overflow。请尽快阅读FAQ。我已经为你整理了代码的缩进(避免在 SO 上使用标签;它们会造成麻烦)。我不确定的唯一一行是最后一行,
first_room(False)。它可能是函数的一部分,也可能是函数之后的单独语句(或者它可能打算在第一个if的else:之后出现)。如果我选择了错误的缩进,请编辑函数。 -
@JonathanLeffler,很确定最后一行应该有凹痕
-
@gnibbler:鉴于 OP 的编辑,看来您是正确的。
标签: python text path boolean adventure