文本游戏 - 将输入文本转换为小写 - Python 3.0

Ant*_*one -1 python text input lowercase

((针对上述编辑,上述链接未对此进行回答.上述问题与我的预期用途无关.))

我读过一个关于将字符串变成小写的类似问题;

如何在Python中将字符串转换为小写

我理解这是如何完美的,但是我自己的尝试失败了.

这是我当前调试块的设置示例;

#Debug block - Used to toggle the display of variable data throughout the game for debug purposes.
def debug():
    print("Would you like to play in Debug/Developer Mode?")
    while True:
        global egg
        choice = input()
        if choice == "yes":
            devdebug = 1
            break
        elif choice == "Yes":
            devdebug = 1
            break
        elif choice == "no":
            devdebug = 0
            break
        elif choice == "No":
            devdebug = 0
            break
        elif choice == "bunny":
            print("Easter is Here!")
            egg = 1
            break
        else:
            print("Yes or No?")
 #
Run Code Online (Sandbox Code Playgroud)

所以,我预先编写了一个不同的大写字母.但是,我想if每个单词只使用一个语句,而不是使用两个语句来大写.我确实有一个想法,它使用另一个块来确定一个真假状态,这看起来像这样;

def debugstate():
    while True:
        global devstate
        choice = input()
        if choice == "Yes":
            devstate = True
            break
        elif choice == "yes":
            devstate = True
            break
        elif choice == "No":
            devstate = False
            break
#Etc Etc Etc
Run Code Online (Sandbox Code Playgroud)

但是使用这个块只需要我已经拥有的代码行,并将其移动到其他地方.我知道我可以设置它,如果它不是'是',那么else可以自动设置devstate为0,但我更喜欢有一个更受控制的环境.我不想意外地用空格键入'yes'并且关闭了devmode.

所以回到这个问题;

我该怎么做才能做到以下几点?

def debug():
    print("Debug Mode?")
    while True:
        global egg
        choice = input()
        if choice == "yes" or "Yes":
            devdebug = 1
            break
        elif choice == "no" or "No":
            devdebug = 0
            break
        elif choice == "egg":
            devdebug = 0
            egg = 1
            print("Easter is Here")
            break
        else:
            print("Yes or No?")
#
Run Code Online (Sandbox Code Playgroud)

上面的代码可能不是最好的例子,但是当我说if每个单词只需要一个语句时,它至少可以帮助我理解.(另外,我希望我不只是在这里解决我自己的问题xD.)

那么,我该怎么做?

((另外,我去这里而不是Python论坛的原因是因为我更喜欢以自己的方式提出我的问题,而不是试图将一个问题的答案拼凑起来,而这个问题对于其他人来说是不同的.))

Rod*_*yde 6

使用.lower()是您的最佳选择

choice = input()
choice = choice.lower()
if choice == 'yes':
    dev_debug = 1
    break
Run Code Online (Sandbox Code Playgroud)

或者使用'in'

choice = input()
if choice in ('yes', 'Yes'):
    dev_debug = 1
    break
Run Code Online (Sandbox Code Playgroud)