python 3列表对象不可调用

时间:2018-11-17 12:17:23

标签: python python-3.x

import csv
def loadQuestions():

    Question_List = []
    Answer_List = []

    with open('Questions.csv', 'r') as myfile:
        reader = csv.reader(myfile)
        for row in reader:
            if row != ['Question', 'Answer']:
                Question_List.append(row[0])    
                Answer_List.append(row[1])   
    return Question_List, Answer_List


def main():
    print('Welcome to my Bio Quiz! You are given the question and a possible answer or a true or false statment.')
    while True:     
        print('Access granted!\nYou can now access the quiz\n')
        Questions, Answers = loadQuestions()
        print('\nQuiz starting now!')
        score = Questions(Answers, Questions)

这是正常运行的最低要求。

当我运行它时,它将一直运行到第22行,它将在该行显示语法错误列表对象不可调用

1 个答案:

答案 0 :(得分:0)

Questions, Answers = loadQuestions()

在loadQuestions函数调用上方,将返回两个列表。

score = Questions(Answers, Questions)

现在,您再次对名为Questions的变量进行函数调用,该变量的类型为loadQuestions()函数返回的列表(第20行),因此会出现错误。

您必须更改变量Questions的名称(第20行)或更改希望在score = Questions()调用的函数的名称(第21行)。