Tell us what’s happening:
the code runs perfectly I don’t understand why it dosen’t pass the test can someone help ?
Your code so far
def arithmetic_arranger(problems, show_answers = False):
list_of_problemes = problems
numbers = []
operators = []
upper_row = []
middel_row = []
hashes = []
results = []
for problem in list_of_problemes:
if len(list_of_problemes) > 5 :
return print('Error: Too many problems.')
else:
array = problem.split()
numbers.append(array[0])
numbers.append(array[2])
operators.append(array[1])
for number in numbers:
if len(number) > 4:
return print('Error: Numbers cannot be more than four digits.')
elif not number.isdigit():
return print('Error: Numbers must only contain digits.')
for op in operators:
if not op in ['+', '-']:
return print("Error: Operator must be '+' or '-'.")
for i in range(0, len(numbers), 2):
num1 = int(numbers[i])
num2 = int(numbers[i + 1])
hashes.append('-' * (max((len(numbers[i]), len(numbers[i + 1]))) + 2) )
lenth = len(hashes[i // 2])
upper_row.append(numbers[i].rjust(lenth, ' '))
x = operators[i // 2] + numbers[i + 1].rjust(lenth-1, ' ')
middel_row.append(x)
if show_answers == True:
if operators[i // 2] == '+':
result = num1 + num2
elif operators[i // 2] == '-':
result = num1 - num2
else:
result = ''
results.append(str(result).rjust(lenth,' '))
upper_row = " ".join(upper_row)
middel_row = " ".join(middel_row)
hashes = " ".join(hashes)
results = " ".join(results)
return print(f'{upper_row} \n{middel_row} \n{hashes} \n{results}')
arithmetic_arranger(["32 - 698", "1 - 3801", "45 + 43", "123 + 49", "988 + 40"], True)
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Challenge Information:
Build an Arithmetic Formatter Project - Build an Arithmetic Formatter Project