繁体   English   中英

如何让我的下一个 elif 语句打印?

[英]How to get my next elif statements to print?

这是我的问题代码。

print('=================================================================================================\n')

prompt = input(f'''\tYou and your family are camping out in a forest near the tetons.
Once the sun goes down and your campground is dark you and your family decide to go to
bed but all of you forgot to light a fire and there are no lamps to light the way. However you find
a {'MATCH'} and a {'FLASHLIGHT'}. Which one do you pick up? ''').lower()
print('-------------------------------------------------------------------------------------------------\n')

RUN = ''
HIDE = ''
match = ''
if prompt.lower() == 'match':
    match = input(f'''\tYou pick up the match and strike it, and for an instant, the forest around you is
    illuminated. You see a large grizzly bear, and then the match burns out.
    Do you want to {'RUN'} or {'HIDE'} behind a tree? ''').lower()
elif match.lower() == 'RUN':
    RUN = print(f'''gfsfdg ''')
elif match.lower() == 'HIDE':
    HIDE = input(f'''fgsbsgf ''')

您只需要match.upper()或将比较字符串切换为小写!

>>> match = "run"
>>> match.lower() == 'RUN'
False
>>> match.upper() == 'RUN'
True

在 if/elif/else 结构中,要匹配的第一个条件将停止对以下条件的评估。

在您的代码中,这意味着当 prompt.lower() == "match" 为真时,elif 将被忽略。

您需要将测试放在另一个 if/elif 结构中的 match.lower() 上。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM