Tell us what’s happening:
I have completed most of the code, aside from adding the answers where necessary, but no matter what I try I cannot get the equations to appear side by side, everything I try either has no effect or breaks it altogether. Please can someone point me in the right direction I’ve been struggling for hours
Your code so far
def arithmetic_arranger(problems, show_answers=False):
# creating the loop
for problem in problems:
# defining the variables
first_number = problem.split()[0]
operator = problem.split()[1]
second_number = problem.split()[2]
second_row = ''
dashes = ''
top_row = ''
# Running the checks
if len(problems) > 5:
return "Error: Too many problems."
if operator == '*' or operator == '/':
return("Error: Operator must be '+' or '-'.")
break
if not first_number.isdigit() or not second_number.isdigit():
return('Error: Numbers must only contain digits.')
break
if len(first_number) > 4 or len(second_number) > 4:
return('Error: Numbers cannot be more than four digits.')
break
# creating the padding
space = max(len(first_number), len(second_number)) + 2
top_row += first_number.rjust(space)
second_row += operator
second_row += second_number.rjust(space-1)
dashes += '-' * space
# compiling the equations
arranged_problems = '\n'.join((top_row, second_row, dashes))
print(arranged_problems)
print(f'\n{arithmetic_arranger(["32 + 698", "3801 - 2", "45 + 43", "123 + 49"])}')
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:134.0) Gecko/20100101 Firefox/134.0
Challenge Information:
Build an Arithmetic Formatter Project - Build an Arithmetic Formatter Project