gpt4 book ai didi

python - 如果您使用 lower 和 caps 作为搜索名称,我需要这个工作(它为 cap 和 lower 提供了不同的内容)

转载 作者:太空宇宙 更新时间:2023-11-03 18:36:49 26 4
gpt4 key购买 nike

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.")

最佳答案

一个简单的方法是将两个字符串都转换为小写。

改变

if surname in line:

if surname.lower() in line.lower():

关于python - 如果您使用 lower 和 caps 作为搜索名称,我需要这个工作(它为 cap 和 lower 提供了不同的内容),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21407974/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com