为什么我在python中得到“tuple”object is not callable error

2024-09-28 20:48:25 发布

您现在位置: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])

Tags: theforlenreturndefprintmarkslenlist
1条回答
网友
1楼 · 发布于 2024-09-28 20:48:25

您为print名称分配了一个元组:

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

现在print被绑定到一个元组,所以当您以后使用它来打印时,您会得到一个错误。从此以后,您就不能再使用内置的print函数。在

您可能只是想在那里打印,而不是生成元组:

^{pr2}$

相关问题 更多 >