Tell us what’s happening:
I dont know what i missing in the code all the rules were done, if any body know please help me
Your code so far
def arithmetic_arranger(problems, show_answers=False):
output = {'line_1':'', 'line_2':'', 'line_3': '', 'line_4': ''}
#Make an error for problom if it is more than 5
if len(problems) > 5 :
return print('Error: Too many problems.')
for problem in problems:
problem_list = problem.split(" ")
# Make an error for numbers if it is not digit
if problem_list[0].isnumeric() == False or problem_list[2].isnumeric() == False:
return print('Error: Numbers must only contain digits.')
first_num = problem_list[0]
operator = problem_list[1]
second_num = problem_list[2]
if operator == "+":
answer = int(first_num) + int(second_num)
elif operator == "-":
answer = int(first_num) - int(second_num)
# Make an error for Operator if it is not + or -
else:
return print("Error: Operator must be '+' or '-'.")
# Make an error for Numbers if it is more than 4 digits
if len(first_num) > 4 or len(second_num) > 4:
return print('Error: Numbers cannot be more than four digits.')
if int(first_num) > int(second_num):
line_1 = first_num.rjust(len(first_num)+2) + ' ' * 4
line_2 = operator + " " + second_num.rjust(len(first_num)) + ' ' * 4
line_3 = "-" * (len(first_num) + 2) + ' ' * 4
line_4 = str(answer).rjust(len(first_num)+2)+ ' ' * 4
else:
line_1 = first_num.rjust(len(second_num)+2) + ' ' * 4
line_2 = operator + " " + second_num.rjust(len(second_num)) + ' ' * 4
line_3 = "-" * (len(second_num) + 2) + ' ' * 4
line_4 = str(answer).rjust(len(second_num)+2)+ ' ' * 4
output['line_1'] += line_1
output['line_2'] += line_2
output['line_3'] += line_3
output['line_4'] += line_4
#print(output)
if show_answers:
print(f"{output['line_1']}\n{output['line_2']}\n{output['line_3']}\n{output['line_4']}")
else:
print(f"{output['line_1']}\n{output['line_2']}\n{output['line_3']}")
arithmetic_arranger(["32 - 698", "1 - 3801", "45 + 43", "123 + 49", "988 + 40"], True)