-1

i am new to python i am geeting the error TypeError: 'str' object is not callable

when input is

3
111+23
1638-1350
1992+133

then porgram run successfully but when the input string contain '*' means my else condition then it throe TypeError

for example if input is

3
111*23
1638-1350
110+456

then got the error TypeError: 'str' object is not callable

here is my code link to ideone code-> http://ideone.com/bDuXpW

def MAX(a,b,c):
    if(a>b and a>c):
        return a
    elif(b>a and b>c):
        return b
    else:
        return c

t=input()
for x in range(0,t):
    myinput=raw_input()
    if(myinput.find('+')!=-1):
        num1,num2=myinput.split('+')
        result=int(num1)+int(num2)
        result_str=str(result)
        num2='+'+num2
        len1=len(num1)
        len2=len(num2)
        len3=len(result_str)
        max=MAX(len1,len2,len3)
        line='-'*max
        num1=' '*(max-len1)+num1
        num2=' '*(max-len2)+num2
        result_str=' '*(max-len3)+result_str
        print num1
        print num2
        print line
        print result_str
        print '\n'
    elif(myinput.find('-')!=-1):
        num1,num2=myinput.split('-')
        result=int(num1)-int(num2)
        result_str=str(result)
        num2='-'+num2
        len1=len(num1)
        len2=len(num2)
        len3=len(result_str)
        max=MAX(len1,len2,len3)
        line='-'*max
        num1=' '*(max-len1)+num1
        num2=' '*(max-len2)+num2
        result_str=' '*(max-len3)+result_str
        print num1
        print num2
        print line
        print result_str
        print '\n'
    else:
        num1,num2=myinput.split('*')
        result=int(num1)*int(num2)  
        result_str=str(result)
        num1_int=int(num1)
        ascii_num2=[]
        for y in num2:
            ascii_num2.append(ord(y)-48)
        mul_list=[]
        k=0
        num2='*'+num2
        len1=len(num1)
        len2=len(num2)
        len3=len(result_str)
        max=MAX(len1,len2,0)
        line='-'*max
        for dig2 in  reversed(ascii_num2):
            new=dig2*(num1_int)
            new_str=str(new)+' '*k
            mul_list.append(new_str)
            k+=1        
        count=len(mul_list)
        max=MAX(len1,len2,len3)
        num1=' '*(max-len1)+num1
        num2=' '*(max-len2)+num2
        line=' '*(max-len(line))+line
        another_line='-'*max
        for i in range(0,count):
            str=mul_list[i]
            str=' '*(max-len(str))+str
            mul_list[i]=str
        print num1
        print num2
        print line
        for i in range(0,count):
            print mul_list[i]
        print another_line
        print result_str
        print '\n'
        result=0
    #....print num1,num2
4
  • 6
    Feel like sharing the traceback? Commented Jul 15, 2013 at 8:37
  • Could you post the whole traceback? Commented Jul 15, 2013 at 8:38
  • 5
    Why would you invent your own max function? Commented Jul 15, 2013 at 8:41
  • Also, for the future, don't call a variable or a function identical to a reserved word, like "max". These kind of things can get you in a lot of trouble and are sometimes hard to identify. Commented Oct 31, 2014 at 20:45

1 Answer 1

8

If you had posted the full traseback as asked, people could have you helped faster.

But I found the issue nevertheless: you overwrite the builtin str with another object:

    another_line='-'*max
    for i in range(0,count):
        str=mul_list[i]
        str=' '*(max-len(str))+str
        mul_list[i]=str

After this, str isn't the builtin string type any longer, but a concrete, program-dependent value.

A call like

str(new)

will fail afterwards, as the newly-assigned value isn't callable, unlike the original type.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.