Tell us what’s happening:
I can’t understand the error message
Your code so far
import re
def arithmetic_arranger(problems, solve=False):
if(len(problems) > 5):
return(“Error: Too many problems”)
first = “”
second = “”
lines = “”
operator = “”
string = “”
for item in problems:
if(re.search(“[^\s0-9.±]”, item)):
if re.search(r"/|*", item):
return “Error, operator must be ‘+’ or ‘-’.”
return “Only digits are accepted.”
firstnum = item.split()[0]
operator = str(item.split()[1])
secondnum = item.split()[2]
if len(firstnum) > 5 or len(secondnum) > 5:
return("maaaximum length is 4 numbers please.")
sum = ""
if operator == "+":
sum = str(int(firstnum) + int(secondnum))
elif operator == "-":
sum = str(int(firstnum) - int(secondnum))
length = max(len(firstnum), len(secondnum)) + 2
top = str(firstnum).rjust(length)
bottom = operator + str(secondnum).rjust(length - 1)
line = ""
res = sum.rjust(length)
for s in range(length):
line += '-'
sumx = ""
if item != problems[-1]:
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:
Opera or whatever it says below here
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 OPR/101.0.0.0
Challenge: Scientific Computing with Python Projects - Arithmetic Formatter
Link to the challenge:
My replit -