 # Arithmetic arranger testing issue

Hi,

I have been giving the arithmetic arranger challenge a go, but have run into an issue. The code I have made works when I test it in sublime, but when I try on repl it fails. I am struggling to understand what exactly is wrong. Could anyone give me a nudge in the right direction?

``````import re

if len(equations)>4:
print('Error: Too many problems')
return
'''setting up local variables'''
numbers=[]
operators=[]
dividingline='-----'''
'''looping through the equations'''
for e in equations:
'''checking if there are letters'''
c=re.search('[a-zA-Z]', e)
if c is not None:
print('Error: Numbers must only contain digits.')
return
'''pulling the numbers out'''
y=re.findall('[0-9]+', e)
'''checking if each set of numbers is 4 digits maximum'''
if len(y)>4:
print('Error: Numbers cannot be more than four digits.')
return
if len(y)>4:
print('Error: Numbers cannot be more than four digits.')
return
'''pulling the operator out'''
z=re.findall('[+-]', e)
'''checking if the operator is + or -, or if there are multiple operators'''
if len(z) <1:
print("Operator must be '+' or '-'")
return
if len(z) >1:
print('Expressions can only have one operator')
return
'''setting the calculation to + or -'''
if z=='+':
operator=1
if z=='-':
operator=2
'''performing the calculation'''
if operator==1:
if operator==2:
'''saving all the results'''
numbers.append(y)
numbers.append(y)
operators.append(z)

'''printing results'''
print(f'{numbers.rjust(6)}    {numbers.rjust(6)}    {numbers.rjust(6)}    {numbers.rjust(6)}')
print(f'{operators} {numbers.rjust(4)}   {operators} {numbers.rjust(5)}    {operators} {numbers.rjust(4)}    {operators} {numbers.rjust(4)}')
print(f'{dividingline.rjust(6)}    {dividingline.rjust(6)}    {dividingline.rjust(6)}    {dividingline.rjust(6)}')
'''checking if answers should be shown, and printing'''

arithmetic_arranger(["32 + 698", "3801 - 2", "45 + 43", "123 + 49"], True)
``````

your function needs to output the strings using the return statement

Thanks, that makes sense. Unfortunately there is obviously something I am missing about return statements.

I rearranged the code to save the string as the variable arranged_problems.

``````	arranged_problems=f"{numbers.rjust(6)}    {numbers.rjust(6)}    {numbers.rjust(6)}    {numbers.rjust(6)}\n{operators} {numbers.rjust(4)}   {operators} {numbers.rjust(5)}    {operators} {numbers.rjust(4)}    {operators} {numbers.rjust(4)} \n{dividingline.rjust(6)}    {dividingline.rjust(6)}    {dividingline.rjust(6)}    {dividingline.rjust(6)}"
return arranged_problems

print(arithmetic_arranger(["98 + 375", "3801 - 2", "45 + 43", "123 + 49", "5+9"]))
``````

However, this returns “None”. If instead I set arranged_problems as a global variable, have the function use the global version and then print the global version after the function was called I get the correctly formatted version.

``````arithmetic_arranger(["98 + 375", "3801 - 2", "45 + 43", "123 + 49"])
print(arranged_problems)

``````
``````98      3801        45       123
``````
• 375 - 2 + 43 + 49

[Finished in 0.3s]
(when running the file it ended correctly aligned but copying it here changed it)

I am sure I am missing something obvious, I just can’t quite find it. Any help would be greatly appreciated.

Thank you

if you give the link to your repl and/or give the full code, it’s much easier to debug

right now I would just play the guessing game in figuring out what’s the issue