所以我有了這個程序,它基本上是在加密許多不同的方式全文(考試的做法),我不知道如何使菜單功能藏漢接受大寫字母爲小寫字母Python 2.7版接受大寫字母
def GetMenuChoice():
MenuChoice = raw_input()
print
return MenuChoice
所以我有了這個程序,它基本上是在加密許多不同的方式全文(考試的做法),我不知道如何使菜單功能藏漢接受大寫字母爲小寫字母Python 2.7版接受大寫字母
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"
演示:
Enter your choice: menu
Try again
Enter your choice: mennu
Try again
Enter your choice: mEnU1
Correct input
如果你想寫終端應用程序,我強烈建議使用curses。但作爲一種快速入侵,只需將其轉換爲較小或大寫,然後再進行檢查。
>>> MenuChoice = raw_input()
A
>>> MenuChoice = MenuChoice.lower()
>>> MenuChoice
'a'
這是你總可以應付一個情況下,在用戶輸入上調用.lower
或.upper
。
謝謝,我現在擁有它:) – user1655562 2013-05-03 08:52:32