Tell us what’s happening:
Hello! I am working on the Arhitmetic Formatter challenge, for the Scientific Computing with Python Certificate. I am stuck with one of the errors shown in the console, which I think also affects the following error (because the error message F alters the format of the next printout). It happens to me that I can’t understand what the first error shown on the console refers to. “Expected different output …”. What can be the reason for this error?
I would be very grateful if someone could help me. I do not know what else to do.
Your code so far
def arithmetic_arranger(problems, displayed = False):
allowed_operations = {"+": "+", "-":"-"}
if len(problems)>5:
return "Error: Too many problems."
linea = ""
linec = ""
linedash = ""
lineresult = ""
for operation in problems:
opsp = operation.split()
a = opsp[0]
b = opsp[1]
c = opsp[2]
if len(a)>4 or len(c)>4:
return "Error: Numbers cannot be more than four digits."
elif b not in allowed_operations:
return "Error: Operator must be '+' or '-'."
elif not a.isdigit() or not c.isdigit():
return "Error: Numbers must only contain digits."
else:
result = eval(a + b + c,{"__builtins__": {}}, allowed_operations)
maxvalue = max(len(str(a)),len(str(c)), len(str(result)))
dash = '-' * maxvalue + '--'
aligna = " " * (len(dash) - len(a))
alignc = " " * (len(dash) - len(c) - 1)
alignresult = " " * (len(dash) - len(str(result)))
linea += aligna + a + " "
linec += b + alignc + c + " "
linedash += dash + " "
lineresult += alignresult + str(result) + " "
if displayed == True:
arrange = linea + "\n" + linec + "\n" + linedash + "\n" + lineresult
elif displayed == False:
arrange = linea + "\n" + linec + "\n" + linedash
arranged_problems = print(arrange)
return arranged_problems
The console:
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36
.
Challenge: Arithmetic Formatter
Link to my repl.it project:
link
Link to the challenge: