Arithmetic Formatter: wont accept my answer but it looks right :(

hello everyone!

can someone help figure out why the wont accept my answer even though it looks right (im not sure on reading the error message ) on my local IDE. im new to python

thank you so much!

this is my code

import re

def arithmetic_arranger(problems, *args):

  if len(problems) > 5:
    return 'Error: Too many problems.'
  answer_row0 = ''
  answer_row1 = ''
  answer_row2 = ''
  answer_row3 = ''

  for num in problems:
    temp = num.split()
    spaces = "    "
    max_length = max(len(temp[0]), len(temp[2]))
    #divider length
    divider = (max_length+2) * ('-') 
    if max_length > 4:
      return 'Numbers cannot be more than four digits.'
    if'[\D]',temp[0]+temp[2]) != None:
      return 'Error: Numbers must only contain digits.'
    answer_row0 += "  {:>{width}}{}".format(temp[0], spaces, width = max_length)
    answer_row1 += '{} {:>{width}}{}'.format(temp[1], temp[2], spaces, width = max_length)
    answer_row2 += '{}{}'.format(divider, spaces)
    #check for + or -
    if args:
      if temp[1] == '+':
        sum = int(temp[0]) + int(temp[2])
      elif temp[1] == '-':
        sum = int(temp[0]) - int(temp[2])
        return 'Error: Operator must be '+' or '-'.'
      answer_row3 += "{:>{width}}{}".format(sum, spaces, width = (max_length+2))

  #stringing strings
  answer = "%s\n%s\n%s" % (answer_row0, answer_row1, answer_row2)
  if args:
    answer += ('\n' + answer_row3)

  return answer

should i include the error message?

That always helps.

I’d guess that you have extra whitespace at the end of each line.

thank you so much, you were right!

there was also 2 more errors:

but i fixed them thank you so much @JeremyLT ! have a great day !

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