记忆引文python程序

2024-03-28 21:53:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我想创建一个程序,我可以记住一本书的所有引用或从某些字符。一旦选择了测试类型,我想输入一个我能记住的引号,如果它存在于文件中,那么我可以继续输入更多的引号。完成后,会给出一个分数。老实说,这是我已经做的一切-我需要一点帮助所有的AIC

def displayMenu():
    print('Inspector Calls quotes:')
    print('1. All AIC quotes')
    print('2. Arthur quotes')
    print('3. Sheila quotes')
    print('4. Inspector quotes')
    print('5. Eric quotes')
    print('6. Gerald quotes')
    # INPUT menu item
    i = input('Please select an option from the menu above(1-6):')
    # VALIDATION of menu item
    while not (i.isnumeric() and int(i)>=1 and int(i)<=6):
        i = input('Error - Please select an option from the menu above(1-3):')
    return i # RETURN menu item

while True:
    choice = displayMenu()
    if choice=='1':
        all_AIC()
    elif choice=='2':
        arthur()
    elif choice=='3':
        sheila()
    elif choice=='4':
        inspector()
    elif choice=='5':
        eric()
    elif choice=='6':
        gerald()
    else:
        print('Wrong choice - enter valid number')

def all_AIC(): # Def means defigning a function
    print('Write your quotes, press # to finish')
    quotes = input('Quotes:') #INPUT username
    quotes = quotes.lower()
    quotefile = open('all_AIC.txt', 'r')
    quotelist = quotefile.readlines()
    quotefile.close()
    found = False
    for line in quotelist:
        if str(quotes) in line:
            print(line)
            found = True

    if not found:
        print('Quote not found')
        quotefile.close()

Tags: inputiflinenotaicallitem引号