Arithmetic Formatter | Output is correct but not exactly like expected output

I recently completed the Arthimetic Formatter for python, which works in python, but when I run it in replit I fail all the tests.Just for context, I didn’t create the program within replit, instead i created it within python. So when it came to testing, I just copied and pasted the questions from test_module.py into the arithmetic_arranger object within the bottom of my code.

So my question is does it matter if my code produces the same results visually but not coded identically to the expected outcome?

For example the expected outcome for first question within test_module.py is:

'  3801      123\n-    2    +  49\n------    -----'

However my answer for the same question within test_module.py, was arranged by using:

arranged_problems = print(top),  print(middle),  print(divider),  print(solution)

To create this:

  3801      123    
-    2    +  49    
------    -----  
     

Do I need to revise the program to get the exact same results that they expect?
and
Does that also mean I won’t get the certificate to prove that I have completed the assignment?

My Code to the assignment (if anyone is interested):

import re

def arithmetic_arranger(problems, answer = False):
    top = ''
    middle = ''
    divider = ''
    solution = ''
    count = 0
    for problem in problems:
        count += 1
        while count > 5:
            print('Error: Too many problems.')
            quit()
        max_digits = problem.split(' ')
        for x in max_digits:
            if len(x) >= 5:
                print('Error: Numbers cannot be more than four digits.')
                quit()
        if re.findall('[A-za-z]',problem):
            print('Error: Numbers must only contain digits.')
            quit()
        if re.findall('[*/%=]',problem):
            print("Error: Operator must be '+' or '-'.")
            quit()
        max_digits = problem.split(' ')
        for x in max_digits:
            if len(x) >= 5:
                print('Error: Numbers cannot be more than four digits.')
                quit()

        top_space = ''
        middle_space = ''
        dashes = ''
        solution_space = ''
        if len(problem.split(' ')[0]) > len(problem.split(' ')[2]):
            middle_count = int(len(problem.split(' ')[0])) - int(len(problem.split(' ')[2]))
            top_space = ''
            while middle_count > 0:
                middle_space += ' '
                middle_count -= 1

        elif len(problem.split(' ')[0]) < len(problem.split(' ')[2]):
            top_count = int(len(problem.split(' ')[2])) - int(len(problem.split(' ')[0]))
            middle_space = ''
            while top_count > 0:
                top_space += ' '
                top_count -= 1

        top = top + '  ' + top_space + problem.split(' ')[0] + '    '
        middle = middle + problem.split(' ')[1] + ' ' + middle_space + problem.split(' ')[2] + '    '

        for x in problem.split(' ')[1] + ' ' + middle_space + problem.split(' ')[2]:
            dashes += '-'

        divider = divider + dashes + '    '

        solve = 0
        if answer is True:
            if problem.split(' ')[1] == '+':
                solve = int(problem.split(' ')[0]) + int(problem.split(' ')[2])
            elif problem.split(' ')[1] == '-':
                solve = int(problem.split(' ')[0]) - int(problem.split(' ')[2])
        else:
            continue
        str_solve = str(solve)
        solution_count = int(len(problem.split(' ')[1] + ' ' + middle_space + problem.split(' ')[2])) - int(len(str_solve))
        while solution_count > 0:
            solution_space += ' '
            solution_count -= 1
        solution = solution + solution_space + str_solve + '    '


    arranged_problems = print(top),
    print(middle),
    print(divider), print(solution)

    return arranged_problems

arithmetic_arranger(['3801 - 2', '123 + 49'])

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:96.0) Gecko/20100101 Firefox/96.0

Challenge: Arithmetic Formatter

Link to the challenge:

Sorry but that’s garbage ^^°
print has no return value, so you assign nothing there.

Yes, if you work on a job and you have to produce a specific output, you cannot stop until you produce the specified output.
Later on, there are people who rely on your work and they won’t take a “but it looked good” as an excuse as to why they have invest 10 times the work to make their code work because you think passing deployment-tests is boring :wink:

Also please provide a link to your replit, so we could run the tests and get the error messages.
However if you actually used print() for your output instead of return, that’s certainly a major issue. That’s like calling a hotline, asking a question and then having the operator write the answer on his notepad. I’m on the phone, I have no idea what’s written there.

1 Like

Thanks for the advice! I appreciate it :smiley:
I didn’t really think too much about the consequences of poor code, but after reading your post it’s helped me understand it a bit clearer now.
I’ll try and revise my code so it fits the criteria for replit!

here’s the URL, but I’ll try and fix this later one when I have the time
https://replit.com/@NahFan/boilerplate-arithmetic-formatter#arithmetic_arranger.py