Scientific Computing with Python Projects - Arithmetic Formatter

main.py
The Replit does not recognize the pytest module.

this is my code so far:

arithmetic_arranger.py

## This is part of the code! ##

import re
def arithmetic_arranger(problems, solve = False):

  if len(problems) > 5:
    return "Error: Too meny problems."

  first= ''
  second= ''
  lines= ''
  sumx=''
  string=''

  for problem in problems:
    if(re.search("[^\s0-9.+-]", problem)):
      if(re.search("[/]", problem) or re.search("[*]", problem))
        return "Error: Operation must be + or -."
      return "Error: Numbers must contain digits."

    firstnumber = problems.split(" ")[0]
    operator = problems.split(" ")[1]
    secondnumber = problems.split(" ")[2]
  
    if(len(firstnumber) >= 5 or len(secondnumber) >= 5):
      return "Error: Numbers must be 4 digits."

    sum = ''
    
    if(operator == to "+"):
      sum = str(int(firstnumber) + int(secondnumber)
    elif(operator == "-"):
      sum = str(int(firstnumber) - int(secondnumber))

    length = max(firstnumber, secondnumber)
    top = str(firstnumber).rjust(length)
    bottom = operator + str(secondnumber).rjust(length)
    line = ''
    res = str(sum).rjsut(length)
    
    for r in range(length):
      line += '_'

    if(problem != problems):
      first += top + '  '
      second += top + '  '
      lines += top + '  '
      sumx += top + '  '
    else:
      first += top
      second += bottom
      lines += line
      sumx += res


    if solve:
      string = first + "/n" + second + "/n" + lines + "/n" + sumx
    else:
       string = first + "/n" + second + "/n" + lines 

    return string

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0

Challenge: Scientific Computing with Python Projects - Arithmetic Formatter

Link to the challenge:

What error message do you get exactly?

Can you please link to your replit?

sure,

credits to London Shlangen -YT

At the Shell command prompt type “pip install pytest”

That will install the pytest module. If it ever says this error “No module named module” Just try “pip install module” and it should install.

This code has so many errors

:joy: This code has so many learning opportunities

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