Tell us what’s happening:
I have written the complete code but it is saying there is some error in line 14 can someone help me because when i am trying to adjust the return in that line then it is saying it is out of the indentation so i am not sure where to put the return in line 14
Your code so far
def arithmetic_arranger(problems, show_answers=False):
if len(problems) > 5:
return "Error: Too many problems."
first_line = []
second_line = []
dash_line = []
result_line = []
for problem in problems:
parts = problem.split()
if len(parts) != 3:
return "Error: Each problem must contain two operands and one operator."
num1, operator, num2 = parts
if operator not in ['+', '-']:
return "Error: Operator must be '+' or '-'."
if not(num1.isdigit() and num2.isdigit()):
return "Error: Numbers must only contain digits."
if len(num1) > 4 or len(num2) > 4:
return "Error: Numbers cannot be more than four digits."
width = max(len(num1), len(num2)) + 2
first_line.append(num1.rjust(width))
second_line.append(opreator + num2.rjust(width - 1))
dash_line.append('-' * width)
if show_answers:
result = str(eval(problem))
result_line.append(result.rjust(width))
arrange_problems = (
' '.join(first_line) + '\n' +
' '.join(second_line) + '\n' +
' '.join(dash_line)
)
if show_answers:
arranged_problems += '\n' + ' '.join(result_line)
return arranged_problems
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36
Challenge Information:
Build an Arithmetic Formatter Project - Build an Arithmetic Formatter Project