Tell us what’s happening:
Describe your issue in detail here.
Your code so far
def arithmetic_arranger(problems, results = False):
first = ""
second = ""
lines = ""
sumx = ""
if len(problems) >= 6:
return "Error: Too many problems."
for v in problems:
a = v.split()
firstsnum = a[0]
operator = a[1]
secondnum = a[2]
if (len(firstsnum) >= 5 or len(secondnum) >= 5) :
return "Error: Numbers cannot be more than four digits. "
if not firstsnum.isnumeric() or not secondnum.isnumeric():
return "Error: Numbers must only contain digits"
if ( operator == '-' or operator == '+' ) :
if operator == "-":
sums = str(int(firstsnum) - int(secondnum))
else:
sums = str(int(firstsnum) + int(secondnum))
length = max(len(firstsnum), len(secondnum)) + 2
top = str(firstsnum).rjust(length)
bottom = operator + str(secondnum).rjust(length - 1)
line = ""
res = str(sums).rjust(length)
for s in range(length):
line += "-"
if v != problems[-1]:
first += top + ' '
second += bottom + ' '
lines += line + ' '
sumx += res + ' '
else:
first += top
second += bottom
lines += line
sumx += res
else:
return "Error: Operator must be '+' or '-'. "
if results:
arranged_problems = first + "\n" + second + "\n" + lines + "\n" + sumx
else:
arranged_problems = first + "\n" + second + "\n" + lines
return arranged_problems
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36
Challenge: Arithmetic Formatter
Link to the challenge: