我的python代码不起作用。我已经尝试了很多方法,但我似乎无法做到这一点。谁能告诉我什么是错的?
if not dead:
time.sleep(2)
print('')
print('"Ok next question." She looked at a paper in front of her.')
time.sleep(2)
print('"Where on earth do they a day with 24 hours and a night with 24 hours?"')
time.sleep(2)
if ally:
print('')
print('"Small hint, it starts with A and is a cold desert."')
print('')
answer = input('Which place?:')
else:
answer = input('Which place?:')
if answer == 'Antarctica' or answer == 'antarctica':
time.sleep(2)
print('')
print('She nods. "Correct. Two more.')
if answer != 'Antarctica' and answer != 'antarctica' and ally:
time.sleep(2)
print('')
print('Shaking her head with wide eyes, she looks around carefully.')
time.sleep(2)
print('"The answer is Antarctica." She says, mimicking your voice.')
dead = False
time.sleep(2)
print(''"I can't do that much, so please try to refrain from getting it wrong."'')
if answer != 'Antarctica' and answer != 'antarctica' and not ally:
time.sleep(2)
print('')
print('She sighs. '"I'm sorry."' The fire below comes closer and closer as you fall.')
dead = True
如果我输错了答案,代码似乎就此结束了,而我希望看到如果用户有一个盟友,如果他们没有盟友,它会给出不同的答案他们给出了不同的答案等。 任何帮助将非常感谢!
答案 0 :(得分:2)
一个字符串只能有一个值。用户输入的内容不是“南极洲”和“南极洲”。或者不是“南极洲”......它可以从不两者兼而有之。
由于and
的{{3}}高于or
,因此您当前的陈述基本上是这样,进一步导致意外结果。
if (answer != 'Antarctica') or (answer != 'antarctica' and ally):
if (answer != 'Antarctica') or (answer != 'antarctica' and not ally):
使用and
代替or
:
if answer != 'Antarctica' and answer != 'antarctica' and ally:
if answer != 'Antarctica' and answer != 'antarctica' and not ally:
您还可以利用elif
和else
- 如果已经true
,则无需检查其他条件。
答案 1 :(得分:1)
变化
answer != 'Antarctica' or answer != 'antarctica'
到
answer.lower() != 'antarctica'