I’ve been trying to code the arithmetic formatter, however i can’t seem to make the numbers appear side by side, so instead, i tried thinking about how i can add space between them but same result. I have no idea.
type or paste code here
def arithmetic_arranger(x, y=False):
for i in x:
if len(x) > 5:
print("Error too many problems")
break
a = i.split()
b = a[0]
c = a[1]
d = a[2]
if len(b) > 4 or len(d) > 4:
print("Error: Numbers cannot be more than four digits.")
break
if len(b) > len(c+d):
z = b.rjust(len(c+d)+1)
print(z)
print(c, d)
print("-" * len(b))
try:
if y == True:
e = int(b)
f = int(d)
if c == "+":
num = e+f
ab = str(num)
adjust = ab.rjust(len(c+d)+1)
print(adjust)
elif c == "-":
num = e-f
ab = str(num)
adjust = ab.rjust(len(c+d)+1)
print(adjust)
else:
print("Error: Operator must be '+' or '-")
except:
print("Error: Numbers must only contain digits")
break
elif len(b) <= len(c+d):
z = b.rjust(len(c+d)+1)
print(z)
print(c, d)
print("-" * (len(c+d)+1))
try:
if y == True:
e = int(b)
f = int(d)
if c == "+":
num = e+f
ab = str(num)
adjust = ab.rjust(len(c+d)+1)
print(adjust)
elif c == "-":
num = e-f
ab = str(num)
adjust = ab.rjust(len(c+d)+1)
print(adjust)
else:
print("Error operator must be + or -")
except:
print("Error: Numbers must only contain digits")
break
arithmetic_arranger(["32 + 8", "1 - 3801", "9999 + 9999", "523 - 49"], True)