无法弄清楚为什么我的 else 语句仍在使用负输入调用此函数

Can't figure out why my else statement is still calling this function with negative input

我正在自学 Python 并决定制作一个简短的基于文本的游戏,首先我决定为用户制作一个功能,以确认他们确实想要玩这个游戏“是或否”选项,但是,即使给出“否”输入,游戏功能仍会被调用。任何帮助将不胜感激。

这是我进入游戏的命令提示符:

while i <= 10000000000000000:
    command = input(":")

    if command == "List commands":
        command_list()
        i += 1
    elif command == "Atlas":
        atlas_confirmation()
        i += 1

这是确认用户想玩游戏的提示:

def atlas_confirmation():
    print("Alright, but this one's pretty spooky. Are you sure?")
    yn = input(":")

    if yn == "Yes" or "yes" or "I'm sure" or "Im sure" or "im sure" or "i'm sure":
        atlas_game()
    elif yn == "No" or "no":
        print(command_end)

这是游戏的占位符:

def atlas_game():
    print(placeholder)
    print(command_end)

当给定正输入时,我得到所需的输出:

Uh oh! Looks like this code has yet to be completed, but it will be available soon!
Is there anything else I can do for you?
:

然而,当我给出一个负输入时,输出仍然和上面一样 ^ 就好像我给出了一个正输入,而不是期望的输出:

Is there anything else I can do for you?
:

我预计我的 'if' 陈述在某处是错误的,但我不知道在哪里或为什么。

如有任何帮助,我们将不胜感激,

谢谢。

我认为您需要从 atlas_confirmation() 函数中 return command_end 来检查 while 循环中的中断条件。将您的 atlas_confirmation() 函数更新为:

def atlas_confirmation():
    print("Alright, but this one's pretty spooky. Are you sure?")
    yn = input(":")

    if yn == "Yes" or yn == "yes" or yn == "I'm sure" or yn == "Im sure" or yn == "im sure" or yn == "i'm sure":
        atlas_game()
    elif yn == "No" or yn == "no":
        return command_end

你的 while 循环到此:

while i <= 10000000000000000:
    command = input(":")

    if command == "List commands":
        command_list()
        i += 1
    elif command == "Atlas":
        atlas_confirmation()
        i += 1