python - How can I match input in a case insensitive manner? -
i making mud, or sud can call (singleplayer) way navigate through game type commands.
def level_01_room_01(): choice = raw_input('>: ') if choice == 'north': level_01_room_02()
in case, if user enters north, capital n, code not perceive command. big mess if have enter:
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()
etc.
is there way can fix this, player can type word or wants to?
always lower()
user input before comparing against known strings (and use lower case).
if choice.lower() =='north': ...
Comments
Post a Comment