Tell us what’s happening:
To be perfectly honest I can’t find the issue with my code but it is saying that I am having errors in my code it is saying that there are AssertionError: Expected different output when calling "arithmetic_arranger()
and this is everything I have so far
import re
def arithmetic_arranger(problems, solve=False):
if (len(problems) > 5):
return ("Too many problems to solve limit is 4 ")
first = ""
second = ""
sumx=""
lines=""
string=""
#error catching making sure that the inputs are plus and minus and that the only things that can be entered are digits
for problem in problems:
if (re.search)("[^\s0-9.+-]",problem):
#re.search used to search in the string
if (re.search("[/]",problem) or re.search("[*]", problem)):
return ("Operations can only be Plus Or Minus.")
return ("Numbers must only contain digits.")
#creating the array so that the numbers will be placed correctly
firstNumber = problem.split(" ")[0]
operator = problem.split (" ")[1]
secondNumber = problem.split(" ")[2]
if(len(firstNumber)) >=5 or len(secondNumber) >=5:
return ("Numbers cannot exceed more than 4 digits")
#how the machine will do the adding and subtracting
sum = " "
if (operator == "+"):
sum = str(int(firstNumber) + int(secondNumber))
elif (operator == "-"):
sum = str(int(firstNumber) - int(secondNumber))
length= max(len(firstNumber), len(secondNumber)) + 2
top = str(firstNumber).rjust(length)
bottom = operator + str(secondNumber).rjust(length)
line= ""
res = str(sum).rjust(length)
for s in range(length):
line += ("-")
#prevents space after each number
if problem != problems[-1]:
first += top + ''
second += bottom + ''
lines += line + ''
sumx += res + ''
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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36
Challenge: Scientific Computing with Python Projects - Arithmetic Formatter
Link to the challenge: