Python 如果你使用lower和caps作为搜索名称,我需要这个功能(它为cap和lower提供了不同的内容)
一种简单的方法是将两个字符串都转换为小写 改变Python 如果你使用lower和caps作为搜索名称,我需要这个功能(它为cap和lower提供了不同的内容),python,Python,一种简单的方法是将两个字符串都转换为小写 改变 print("Hello and welcome to your address book this program uses surnames or D.O.B to find people in the address book file.") yn = "" while yn != "n": yn = input ("Would you like to search for a user? (Y/N) ") if yn =
print("Hello and welcome to your address book this program uses surnames or D.O.B to find people in the address book file.")
yn = ""
while yn != "n":
yn = input ("Would you like to search for a user? (Y/N) ")
if yn == "y":
search = input ("Would you like to search by surname (S) or month of birth (M) ")
if search.lower() == "s":
surname = input ("Please enter the surname: ")
for line in open("datafile.txt"):
if surname in line:
print(line)
elif search.lower() == "m":
DMY = input("please enter your date of birth you are looking for (date/month/year) : ")
DMY = DMY.split("/")
DMY = DMY[1]
for line in open("datafile.txt"):
if DMY in line:
print(line)
else:
print ("Sorry you can not do this please try again.")
elif yn == "n":
print("Goodbye")
else:
print("Sorry you can not do this please try again.")
到
你为什么不把
lower()
if surname in line:
if surname.lower() in line.lower():