 # Arithmetic Formatting challenge - solved but still not passing tests

Can someone take a look or try running my solution to the challenge and suggest why it’s not passing the tests?

I’ve ran all the requirements through with CodeRunner and get identical output to the specs but it is still failing in the web app.

``````def arithmetic_arranger(*arguments):
#!check for length of problems
problems = arguments
if len(problems) > 5:
print('Error: Too many problems.')
return 'Error: Too many problems.'
# create a dictionary to store the lines for all the equations
lines_dict = dict()
for item in ['line_1','line_2','line_3','line_4']:
lines_dict[item] = []

for item in problems:
# split item into equation_split
equation_split = item.split()
# extract operands and operator
if len(equation_split) <= 4 and len(equation_split) <= 4:
if isinstance(int(equation_split),int) and isinstance(int(equation_split),int):
operand1 = equation_split
operand2 = equation_split
#print(operand1,operand2)
else:
print('Error: Numbers must only contain digits.')
return 'Error: Numbers must only contain digits.'
else:
print('Error: Numbers cannot be more than four digits.')
return 'Error: Numbers cannot be more than four digits'

if equation_split == '+' or equation_split == '-':
operator = equation_split
else:
print('Error: Operator must be '+' or '-'.')
return 'Error: Operator must be '+' or '-'.'

# calculate length of biggest operand (longest number)
max_operand_len = max(len(operand1),len(operand2))
#print("max operand len",max_operand_len)
# calculate the display length for each equation
display_len = max_operand_len + 2

# 1st line
first_line = ''

## calculate spaces before 1st operand (32)
spaces = display_len - len(operand1)

first_line = spaces * ' '

## add operand to first line

first_line += operand1
lines_dict['line_1'].append(first_line)
#print(lines_dict["line_1"])

# 2nd line
second_line = '{}'.format(operator)

## calculate spaces to line_2
spaces = (display_len - 1) - len(operand2)

second_line += spaces * ' '

second_line += operand2
lines_dict['line_2'].append(second_line)
#print(lines_dict["line_2"].

# 3rd line
third_line = '-' * display_len
lines_dict['line_3'].append(third_line)
#print(lines_dict["line_3"])

# 4th line
fourth_line = ''

if operator == '+':
else:

## calculate spaces

fourth_line = spaces * ' '

lines_dict['line_4'].append(fourth_line)

# join (seperated by 4 spaces) and print the lines in lines_dict
if not arguments.__contains__(True):
lines_dict.__delitem__('line_4')
arranged_problems = ""
for item in lines_dict:
arranged_problems += '    '.join(lines_dict[item]) + '\n'
print(arranged_problems)
#return ("{}\n{}\n{}\n{}".format(first_line,second_line,third_line,fourth_line))
return arranged_problems
``````

You shouldn’t be both printing and returning.

Does this actually work? I would expect that you need to use outer double quotes.