Python 2.7接受大写字母

Python 2.7接受大写字母,python,Python,所以我有了这个程序,它基本上以多种不同的方式对文本进行加密(用于考试练习),我不知道如何让菜单功能接受大写字母和小写字母 def GetMenuChoice(): MenuChoice = raw_input() print return MenuChoice 如果你想编写终端应用程序,我强烈建议你使用。但作为一种快速的破解方法,只需将其转换为小写或大写,然后进行检查。使用str.lower()或str.upper()将文本转换为全小写或全大写: def GetMenuChoice

所以我有了这个程序,它基本上以多种不同的方式对文本进行加密(用于考试练习),我不知道如何让菜单功能接受大写字母和小写字母

def GetMenuChoice():
  MenuChoice = raw_input()
  print
  return MenuChoice

如果你想编写终端应用程序,我强烈建议你使用。但作为一种快速的破解方法,只需将其转换为小写或大写,然后进行检查。

使用
str.lower()
str.upper()
将文本转换为全小写或全大写:

def GetMenuChoice():
  MenuChoice = raw_input("Enter your choice: ")
  return MenuChoice.lower()

expected="Menu1"
while GetMenuChoice() != expected.lower():
    print "Try again"
print "Correct input"    
演示:


这是一种情况,您可以通过调用用户输入的
.lower
.upper
来处理

谢谢,我现在拿到了:)
Enter your choice: menu
Try again
Enter your choice: mennu
Try again
Enter your choice: mEnU1
Correct input
>>> MenuChoice = raw_input()
A
>>> MenuChoice = MenuChoice.lower()
>>> MenuChoice
'a'