为什么我会得到"' tuple' python中的对象不是可调用的错误

时间:2014-07-13 08:08:09

标签: python

这是学校给我的练习练习,我不知道为什么我的列表不可调用,特别是它发生在代码“print(ListName[i],T1AL[i])”中这点是打印出一个列表标记高于平均值的名称

AlphaList = []
T1AL = []
T2AL = []
T3AL = []
ListName = []
def avgmarks():
    #defines a function
    #To get the info from the user and seperates the string and makes the maarks an integer
    #parameters: none
    #reutnrs: avg
    lenlist = len(NameMSplit) - 1
    avg = (Test1 + Test2 + Test3)/lenlist
    return avg

def getname():
    Name1 = str(NameMSplit[0])
    return Name1
def T1A():
    #defines a function
    #getting the average marks for test 1
    #parameters none
    #returns
    SumList=sum(T1AL)
    lenlist=len(T1AL)
    T1Av = SumList/lenlist
    return T1Av

def T2A():
    #defines a function
    #getting the average marks for test 2
    #parameters none
    #returns
    SumList=sum(T2AL)
    lenlist=len(T2AL)
    T2Av = SumList/lenlist
    return T2Av

def T3A():
    #defines a function
    #getting the average marks for test 3
    #parameters none
    #returns
    SumList=sum(T3AL)
    lenlist=len(T3AL)
    T3Av = SumList/lenlist
    return T3Av

#Main Code    
NameMarks = input("Please input your name followed by your marks seperated by spaces")
NameMSplit = NameMarks.split()
while NameMarks != 'Q':
    Test1 = int(NameMSplit[1])
    Test2 = int(NameMSplit[2])
    Test3 = int(NameMSplit[3])
    Name = getname()
    Avg = avgmarks()
    ListName.append(NameMSplit[0])
    T1AL.append(Test1)
    T2AL.append(Test2)
    T3AL.append(Test3)
    T1Avg = T1A()
    T2Avg = T2A()
    T3Avg = T3A()
    Combined = (Name, Avg)
    AlphaList.append(Combined)
    NameMarks = input("Please input your name followed by your marks seperated by spaces")
    NameMSplit = NameMarks.split()
LAlist = len(AlphaList)
for i in range (0,LAlist,1):
    print (AlphaList[i])
print = 'Test 1 Avg:',(T1Avg),'Test 2 Avg:', (T2Avg),'Test 3 Avg:' ,(T3Avg)
T1ALList = len(T1AL)
for i in range(0,T1ALList,1):
        if T1AL[i]>T1Avg:
            print(ListName[i],T1AL[i])
        if T2AL[i]>T2Avg:
            print(ListName[i],T2AL[i])
        if T3AL[i]>T3Avg:
            print(ListName[i],T3AL[i])

1 个答案:

答案 0 :(得分:2)

您为print名称指定了一个元组:

print = 'Test 1 Avg:',(T1Avg),'Test 2 Avg:', (T2Avg),'Test 3 Avg:' ,(T3Avg)

现在print绑定到元组,因此当您稍后使用它来尝试打印时,会出现错误。您无法再使用内置的print功能。

你可能只是想在那里打印,而不是产生一个元组:

print('Test 1 Avg:',(T1Avg),'Test 2 Avg:', (T2Avg),'Test 3 Avg:' ,(T3Avg))