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: