Stuck on Arithmetic Formatter

Hello, I am rather new to python I wanted to try out the curriculum for ‘Scientific Computing with Python’ and I find myself stuck on this particular project for quite sometime and whenever I run the main, test for format and solution will fail as in the solution is not being read or returned. However when I run it on the parameter used in the tests instead of the default parameter given on main.py, it somehow prints the solution out. Is it because of my solution formatting being weird?

def arithmetic_arranger(*problems):

  boolCheck = False
  problems = problems[0]
  numList = ['', '', '', '']
  longest = ''


  for i in problems:

    if type(i) is bool:
      boolCheck = i
      problems = problems[0]

  if len(problems) > 5:
    arranged_problems = "Error: Too many problems."
    return arranged_problems

  for y in problems:
    numOp = y.split()
    num1 = numOp[0]
    oper = numOp[1]
    num2 = numOp[2]

    if oper != '+' and oper != '-':
      arranged_problems = "Error: Operator must be '+' or '-'."
      return arranged_problems

    if len(num1) > 4:
      arranged_problems = "Error: Numbers cannot be more than four digits."
      return arranged_problems

    if len(num2) > 4:
      arranged_problems = "Error: Numbers cannot be more than four digits."
      return arranged_problems

    if num1.isnumeric() == False:
      arranged_problems = "Error: Numbers must only contain digits."
      return arranged_problems

    if num2.isnumeric() == False:
      arranged_problems = "Error: Numbers must only contain digits."
      return arranged_problems

    if len(num1) == len(num2):
      longest = num1
      numList[0] = numList[0] + '  ' + num1 + '    '
      numList[1] = numList[1] + oper + ' ' + num2 + '    '
      for i in range(len(num2) + 2):
        numList[2] = numList[2] + '-'
      numList[2] = numList[2] + '    '

    
    if len(num1) > len(num2):
      longest = num1
      numList[0] = numList[0] + '  ' + num1 + '    '
      spaceHolder = ''
      for i in range(len(num1) - len(num2) + 1):
        spaceHolder = spaceHolder + ' '
      numList[1] = numList[1] + oper + spaceHolder + num2 + '    '
      for i in range(len(num1) + 2):
        numList[2] = numList[2] + '-'
      numList[2] = numList[2] + '    '

    if len(num1) < len(num2):
      longest = num2
      numList[1] = numList[1] + oper + ' ' + num2 + '    '
      spaceHolder = ''
      for i in range(len(num2) - len(num1)+1):
        spaceHolder = spaceHolder + ' '
      numList[0] = numList[0] + ' ' + spaceHolder + num1 + '    '
      for i in range(len(num2) + 2):
        numList[2] = numList[2] + '-'
      numList[2] = numList[2] + '    '

    
    if boolCheck == True:
      spacing = ''
      if oper == '-':
        result = int(num1) - int(num2)
      if oper == '+': 
        result = int(num1) + int(num2)

      for i in range(len(longest) + 2 - len(str(result))):
        spacing = spacing + ' '
      numList[3] =  numList[3] + spacing + str(result) + '    '
  #numList[2] = numList[2]+'\n'+ str(numList[3])

  numList[0] = numList[0].rstrip() + '\n'
  numList[1] = numList[1].rstrip() + '\n'
  numList[2] = numList[2].rstrip() + '\n'
  numList[3] = numList[3].rstrip()

  
  
  arranged_problems = numList[0] + numList[1] + numList[2] +numList[3]

  arranged_problems= arranged_problems.rstrip()
  return arranged_problems

this is the failed return

I am not able to provide an embedded image of the output of main when using the tested parameter for said tests done

I’m willing to give the replit link if it is required for any assistance on this matter.
Replit link:
https://replit.com/join/rhkulnmppy-xyprus-5

Sorry if my English is bad, it is not my first language.

Here is the replit link, Randell.
https://replit.com/join/rhkulnmppy-xyprus-5

You are making things a bit more complicated by using the variable-length positional arguments (`*problems’). You know up front, there will only ever be up to 2 arguments passed to the function, so use that to your advantage.

I see, if that’s the case thank you

I’m not sure if you got the reply but I see the problem now. Thank you

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