# Arithmetic Formatter help beginner

Hi Guys,

i am new in Python or any programming so if someoone could be so kind and help me. I am trying to find mistake in week already and I gave up. It is printing me only first numbers but the rest from output it is not showing. Can someoone help me with that, I would be really happy.

def arithmetic_arranger(problems):

``````    # 1 len
if len(problems) > 5:
return "Error: Too many problems."

for e, number in enumerate(problems, start=0):

num1, operator, num2 = number.split(" ")

num1_len = len(num1)
num2_len = len(num2)
operators = ["+", "-"]

# 2 operator
if operator not in operators:
return "Error: Operator must be '+' or '-'."
# 3 digits
if num1.isdigit() == False:
return "Error: Numbers must only contain digits."
if num2.isdigit() == False:
return "Error: Numbers must only contain digits."
# 4 width
if num1_len > 4:
return "Error: Numbers cannot be more than four digits."
if num2_len > 4:
return "Error: Numbers cannot be more than four digits."

row_1 = ''
row_2 = ''
row_3 = ''
row_4 = ''

if operator == "+":
total = int(num1) + int(num2)
else:
total = int(num1) - int(num2)

#space
space = max(num1_len, num2_len) + 2

extra_space = '    '

row_1 += num1.rjust(space)
row_2 += operator + num2.rjust(space-1)
row_3 += '-' * space
row_4 += str(total).rjust(space)

row_1 += extra_space
row_2 += extra_space
row_3 += extra_space
row_4 += extra_space

if problems:
solution = row_1 + '\n' + row_2 + '\n' + row_3 + '\n' + row_4

else:
solution = row_1 + '\n' + row_2 + '\n' + row_3

return solution

return problems
``````

print(arithmetic_arranger([“32 + 698”, “3801 - 2”, “45 + 43”, “123 + 49”]))

As soon as your function encounters a `return` statement, the function immediately stops. This `return` statement in inside your loop, so your code will only run the loop once, see the `return` statement, and immediately stop.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.