无法在列表中使用if在python3中搜索

时间:2019-12-13 05:45:21

标签: python-3.x

始终搜索功能返回错误的搜索字符串 我正在尝试查找搜索是否符合movie_list并打印true或false

movie_list = []

def menu():
    data = input(' please type A to add S to seach')
    while data != 'q':
        if data == 'a':
            additz()
        elif data == 's':
            searchit()
        else:
            print('unkown command')
        data = input(' please type A to add S to seach')
        print(movie_list)

def additz():
    name = input('please enter movie name')
    year = input('please enter the movie realsed year')
    movie_list.append(
        {
            'name':name,
            'year':year
        }
    )
    return movie_list
    print(movie_list)

def searchit():
    seaching = input('what are you seaching for boy ??')
    if seaching in movie_list:
        print('okay')`enter code here`
    else:print('bad seach')

menu()

1 个答案:

答案 0 :(得分:0)

请检查此代码以进行search()

def searchit():
    seaching = input('what are you seaching for boy ??')
    for i in movie_list:
       #print(i)
       if i['name']==seaching or  i['year']==seaching:
          print('okay')
          menu()
    else:print('bad search')

menu()