我是 python 新手,我遇到了错误TypeError: 'str' object is not callable
当输入是
3
111+23
1638-1350
1992+133
然后 porgram 成功运行,但是当输入字符串包含 '*' 表示我的 else 条件时,它会痛苦TypeError
例如,如果输入是
3
111*23
1638-1350
110+456
然后得到错误 TypeError: 'str' object is not callable
这是我的 ideone 代码链接-> 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