python怎么返回布尔值_尝试从函数返回布尔值

您需要将“return incomp1==True”替换为“return True”。然后像这样调用door1函数“incomp1=door1(incomp1)”。

这将把incomp1的值更改为函数“True”返回的值。在

也可以用简单的“else”替换“elif incomp1==True:”。在

您还可以考虑将.lower()添加到choice1=raw_input(“您的响应是什么?:>;“)。这样一来,如果玩家在输入中使用一个大写字母,它仍然可以按需要工作。在def door1(incomp1):

if incomp1 == False:

print 'You enter door 1 and find a hideous internet troll.'

print "The troll says, 'LOOK AT THIS LOSER'"

options = ["YOU'RE THE LOSER", "I don't care." , "YOUR MOM IS FAT"]

options2 = [1,2,3]

for x in options:

print "\t :> %s" % x

#choice1 = raw_input("What is your response? :>")

choice1 = raw_input("What is your response? :>").lower()

if ('loser' in choice1) or ('fat' in choice1):

print "You are sucked into the troll's behaviour and are driven insane"

print "After three days of insanity, you starve to death"

dead()

elif 'care' in choice1:

print 'The troll cannot feed off of your anger.'

print 'The troll starves and you recover one piece of the lever from his stomach.'

change()

entrywayopen()

return True

else:

unknown()

change()

door1(incomp1)

#elif incomp1 == True:

else:

print 'You already recovered the piece from room 1.'

entrywayopen()

incomp1 = door1(incomp1)

你可能感兴趣的:(python怎么返回布尔值)