Scientific Computing with Python Projects - Arithmetic Formatter - DhiK9iueAd1z4TwGeQnMk

Tell us what’s happening:
So I did the arithmetic formatter exercise and I post the link in the Solution Link box but there is no feedback except a tick next to the project name on the course page.

Does it mean I did it correctly?

Your code so far
https://replit.com/@StephenChan1/UsableResponsibleAdministrator#main.py

def arithmetic_arranger(list1):
  # error 1
  if len(list1) > 5:
    print("Error: Too many problems.")  
  
  # error 2
  for i in list1:
    if i.split()[1] in "+-":
      continue
    else:
      print("Error: Operator must be '+' or '-'.")
  # error 3
    if not i.split()[0].isdigit() and i.split()[2].isdigit():
      print("Error: Numbers must only contain digits.")
  # error 4
    for j in i.split():
      if len(j) <= 4:
        continue
      else:
        print("Error: Numbers cannot be more than four digits.")
        break
  
  # prepare operand and operator list
  operands_top = []
  operators = []
  operands_bot = []
  dashes = []
  results = []
  
  # seperating operands and operators from the given list of strings
  # formatting lists' elements with " "
  for i in list1:      
    length = max(len(i.split()[0]), len(i.split()[2])) + 2
    operands_top.append(i.split()[0].rjust(length, " "))
    operators.append(i.split()[1])
    operands_bot.append(i.split()[2].rjust(length - 1, " "))
    dashes.append("-" * length)

  # print(operands_top)
  # print(operators)
  # print(operands_bot)
  # print(dashes)
  
  # calculate the resutls
  # formatting list's element with " "
  for i in range(len(list1)):
    length = len(dashes[i])
    top = operands_top[i]
    bot = operands_bot[i]
    if operators[i] == "+":
      results.append(str(int(top) + int(bot)).rjust(length, " "))
    else:
      results.append(str(int(top) - int(bot)).rjust(length, " "))
    
  # print(results)

  second_row = []
  for i in range(len(list1)):
    second_row.append(operators[i] + operands_bot[i])

  # print(second_row)
  
  first_row = "    ".join(operands_top)
  second_row1 = "    ".join(second_row)
  third_row = "    ".join(dashes)
  forth_row = "    ".join(results)
  
  print(first_row)
  print(second_row1)
  print(third_row)
  print(forth_row)

  

test_list = ["32 + 698", "3801 - 2", "45 + 43", "123 + 49"]
arithmetic_arranger(test_list)      

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36

Challenge: Scientific Computing with Python Projects - Arithmetic Formatter

Link to the challenge:

You need to run the test suite in relpit. The test suite will tell you if you did it correctly.

Unfortunately, you completely deleted the test suite, so I don’t know if you did the project correctly. Looking at the code, you are using print instead of returning a string, so you have at least one problem with your solution.

1 Like

Oh, I see, thank you, I will make a new one with the test thing.