如何以不区分大小写的方式匹配输入?

Sti*_*tig 0 python

我正在制作MUD或SUD,因为我们可以称之为(单人游戏)导航游戏的唯一方法是键入命令.

def level_01_room_01():
    choice = raw_input('>: ')
    if choice == 'north':
        level_01_room_02()
Run Code Online (Sandbox Code Playgroud)

在这种情况下,如果用户使用大写N输入North,则代码将不会感知此命令.如果我真的必须输入,那将是一个很大的混乱:

def level_01_room_01():
    choice = raw_input('>: ')
    if choice == 'North':
        level_01_room_02()
    if choice == 'north':
        level_01_room_02()
    if choice == 'NORTH':
        level_01_room_02()
Run Code Online (Sandbox Code Playgroud)

等等.

有什么办法可以解决这个问题,这样玩家可以按照自己的意愿输入这个单词吗?

Car*_*ner 5

lower()在将其与已知字符串进行比较之前始终是用户输入(并始终使用小写).

if choice.lower() =='north':
    ...
Run Code Online (Sandbox Code Playgroud)