user3459426
user3459426

Reputation: 81

Why am I getting "'tuple' object is not callable error in python

This was a practice exercise given to me by the school and I do not know why my lists aren't callable, specifically its happening in the code "print(ListName[i],T1AL[i])" The point of this was to print out a list of names which have a mark higher than the average

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])

Upvotes: 0

Views: 2324

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1125018

You assigned a tuple to the print name:

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

Now print is bound to a tuple, so when you later use it to try and print, you get an error. You can no longer use the built-in print function from there on out.

You probably just wanted to print there, not produce a tuple:

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

Upvotes: 2

Related Questions