有一段代码可将用户输入的内容更改为小写,我如何将此代码实现为我的代码而不是使用[“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:”)。 ()' –