I am having issues with this line of code. answerLine = str(answer) ,
The error message is TypeError: ‘list’ object is not callable
I have checked my data type of answer is integer, and I am trying to convert from int to string. I have learned in SO that my “answer” is a list, but I still don’t know how to convert it to string. Any help would be greatly appreciated.
def arithmetic_arranger(str,optional_arg = False):
#If there are too many problems supplied to the function. The limit is five
if len(str) > 5:
print ("Error: Too many problems.")
arranged_problems = []
first_line = ""
second_line = ""
dashline =""
answer = ""
#x is the first digit and z is the second digit
for p in str:
a,op,b = p.split()
num1 = int(a)
num2 = int(b)
if op == "+":
answer = int(a) + int(b)
if op == "-":
answer = int(a)- int(b)
answerLine = str(answer)
#Multiplication and division will return an error.
if op not in ["+", "-"]:
print (" Error: Operator must be '+' or '-'.")
if num1 >= 10000 or num2 >= 10000:
print ("Error: Numbers cannot be more than four digits.")
width = max(len(a), len(b)) + 2
first_line = first_line + a.rjust(width) + " "
second_line = second_line + op + " " + b.rjust(width-2) + " "
dashline = dashline + ("-") * int(width) + " "
answer = answer
if optional_arg == True:
arranged_problems = first_line + "\n" + second_line + "\n" + dashline + "\n" + answer
else:
arranged_problems = first_line + "\n" + second_line + "\n" + dashline
return arranged_problems