Build an Arithmetic Formatter Project - Build an Arithmetic Formatter Project

Tell us what’s happening:

I understand if the second number has more digits, there should only be one space of separation, but if it isn’t, what is the criteria?? I really can’t understand and i think this is the only thing that isn’t letting me pass the more basic tests

Your code so far

def arithmetic_arranger(problems, show_answers=False):
    data = [[], [], []]
    solution = []
    for problem in problems:
        elements = problem.split(' ')
        if len(elements[2]) >= len(elements[0]):
            second = f'{elements[1]} {elements[2]}'
        else:
            second = f'{elements[1]}{" " * (len(elements[0]) - 1)}{elements[2]}'
        
        data[0].append(' '*(len(second) - len(elements[0])) + elements[0])
        data[1].append(second)
        data[2].append('-' * len(second))
    solution.append('    '.join(data[0]))
    solution.append('    '.join(data[1]))
    solution.append('    '.join(data[2]))
    return '\n'.join(solution)

print(f'\n{arithmetic_arranger(["3801 - 2", "123 + 49"])}')

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0

Challenge Information:

Build an Arithmetic Formatter Project - Build an Arithmetic Formatter Project

If you follow the first example output, you can see that 3801 - 2 should be formatted as:

"""
  3801
-    2
------
"""

While you have

"""
 3801
-   2
-----
"""

You should keep one space between the beginning of the longest number and the sign even when they are not on the second line.

One handy tip for debugging the formatting is to use the repr() method with print() so that you can see more clearly how your function output differs from the expected output.

EXAMPLE:

# function output
print(repr(f'\n{arithmetic_arranger(["3801 - 2", "123 + 49"])}'))

# expected output
print(repr('3801      123\n-    2    +  49\n------    -----'))