如果语句语法错误,则在python中创建列表

时间:2018-10-30 19:03:43

标签: python list

我正在创建一个项目,其中包含两个受欢迎的男孩和女孩名字列表。它指示用户输入男孩的名字,然后让他们知道该名字是否流行。我很确定我没事,但是在第18行(如果性别=='g'下的elif语句),我继续遇到语法错误,在elif之后突出显示冒号。如果有人知道为什么那会很有帮助,因为我不知道

def main():
    # Open a file for reading.
    infile = open('GirlNames.txt', 'r')
    infile2 = open('BoyNames.txt', 'r')

    # Read the contents of the file into a list.
    GirlNames = infile.readlines()
    BoyNames = infile2.readlines()

    # Close the file.
    infile.close()

    gender = input('Enter g to search for a girl name, b for a boys name, or both for both')
    if gender == 'g':
        girl = input('Please enter a girls name: ')
        if girl in GirlNames:
            print (girl, "was a popular girl's name between 2000 and 2009")
        elif: 
            print (girl, "was not a popular girl's name between 2000 and 2009")
    if gender == 'b':
        boy = input('Please enter a boys name: ')
        if boy in BoyNames:
            print (boy, "was a popular boy's name between 2000 and 2009")
        elif:
            print (boy, "was not a popular boy's name between 2000 and 2009")
    elif gender == 'both':
        girl1 = input("Please enter a girl's name ")
        boy1 = input("please enter a boy's name ")
        if girl1 in GirlNames:
            print (girl1, "was a popular girl's name between 2000 and 2009")
        if boy1 in BoyNames:
            print (boy1, "was a popular boy's name between 2000 and 2009")


# Call the main function.
main()

0 个答案:

没有答案