有一段代碼可將用戶輸入的內容更改爲小寫,我如何將此代碼實現爲我的代碼而不是使用[「a」或「A」]?將用戶輸入更改爲小寫的代碼
def displaymenu():
print("Weather station")
print("Please enter the option you would like")
optionchoice = input("Please enter A,B,C or D:")
if optionchoice in ["a" or "A"]:
print("The temperature will be displayed")
time.sleep(1)
optionA()
elif optionchoice in ["b" or "B"]:
print("The wind speed will be displayed")
time.sleep(1)
optionB()
elif optionchoice in ["c" or "C"]:
print("The day and time will be displayed")
time.sleep(1)
optionC()
elif optionchoice in ["d" or "D"]:
print("The Location will be displayed")
time.sleep(1)
optionD()
else:
print("Please type a valid input")
displaymenu()
你可以使用'.lower()'強制它小寫 – GreenSaber
我怎樣才能把這個放到我的代碼中,我不完全確定 –
'optionchoice = input(「請輸入A,B,C或D:」)。 ()' –