Scientific Computing with Python Projects - Arithmetic Formatter

I got this error message and i don’t know what is happening

Here’s my code

``````def arithmetic_arranger(problems):
first_line = ""
second_line = ""
dash_line = ""
result_line = ""

for problem in problems:
operand1, operator, operand2 = problem.split()

if operator not in ['+', '-']:
return "Error: Operator must be '+' or '-'."

if not operand1.isdigit() or not operand2.isdigit():
return "Error: Numbers must only contain digits."

if len(operand1) > 4 or len(operand2) > 4:
return "Error: Numbers cannot be more than four digits."

width = max(len(operand1), len(operand2)) + 2
first_line += operand1.rjust(width) + "    "
second_line += operator + operand2.rjust(width - 1) + "    "
dash_line += "-" * width + "    "

if operator == '+':
result = str(int(operand1) + int(operand2))
else:
result = str(int(operand1) - int(operand2))

result_line += result.rjust(width) + "    "

arranged_problems = "\n".join([first_line.rstrip(),
second_line.rstrip(),
dash_line.rstrip(),
result_line.rstrip()])

return arranged_problems

# Test cases
``````

Here’s my main.py code

``````# This entrypoint file to be used in development. Start by reading README.md
from pytest import main

from arithmetic_arranger import arithmetic_arranger

problems = ["32 + 698", "3801 - 2", "45 + 43", "123 + 49"]
arranged_problems = arithmetic_arranger(problems)
print(arranged_problems)

# Run unit tests automatically
main(['-vv'])
``````

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.