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: