Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如果你使用lower和caps作为搜索名称,我需要这个功能(它为cap和lower提供了不同的内容)_Python - Fatal编程技术网

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():