Hey guys, I dont have a clue why my code only fails in the test.
I know it is long, but I thought it should work at least.
Here is the link: boilerplate-arithmetic-formatter - Replit
And also here:
def arithmetic_arranger(arguments, solution=False):
if solution:
tp = []
for word in arguments:
sl = word.split()
tp.append(sl)
for _ in tp:
if len(arguments) < 6:
continue
else:
print("Error: Too many problems.", end="")
exit()
st = 0
for a in tp:
w1 = a[st]
if w1.isnumeric() is True:
continue
else:
print("Error: Numbers must only contain digits.", end="")
exit()
st3 = 2
for a in tp:
w3 = a[st3]
if w3.isnumeric() is True:
continue
else:
print("Error: Numbers must only contain digits.", end="")
exit()
st = 1
mns = "-"
pls = "+"
for a in tp:
w2 = a[st]
if w2 == mns or w2 == pls:
continue
else:
print("Error: Operator must be '+' or '-'.", end="")
exit()
st = 0
for a in tp:
w1 = a[st]
if len(w1) < 5:
continue
else:
print("Error: Numbers cannot be more than four digits.", end="")
exit()
st = 2
for a in tp:
w3 = a[st]
if len(w3) < 5:
continue
else:
print("Error: Numbers cannot be more than four digits.", end="")
exit()
temp = []
for word in arguments:
sl = word.split()
temp.append(sl)
stl1 = 0
stl2 = 1
stl3 = 2
pov = []
n = 0
for b in temp:
wrd1 = b[stl1]
wrd2 = b[stl2]
wrd3 = b[stl3]
n += 1
if n == len(temp):
if len(wrd1) > len(wrd3):
qi = len(wrd1) - len(wrd3)
abst = " " * qi
pov.append(wrd2 + ' ' + abst + wrd3)
elif len(wrd1) == len(wrd3):
pov.append(wrd2 + ' ' + wrd3)
elif len(wrd1) < len(wrd3):
pov.append(wrd2 + ' ' + wrd3)
else:
if len(wrd1) > len(wrd3):
qi = len(wrd1) - len(wrd3)
abst = " " * qi
pov.append(wrd2 + ' ' + abst + wrd3)
elif len(wrd1) == len(wrd3):
pov.append(wrd2 + ' ' + wrd3)
elif len(wrd1) < len(wrd3):
pov.append(wrd2 + ' ' + wrd3)
y = " " * 4
stl = 0
n = 0
for a, los in zip(temp, pov):
wrd1 = a[stl]
n += 1
if n == len(temp):
if len(los) == 6:
print(f"{wrd1: >10}", "\n", end="")
if len(los) == 5:
print(f"{wrd1: >9}", "\n", end="")
if len(los) == 4:
print(f"{wrd1: >8}", "\n", end="")
if len(los) == 3:
print(f"{wrd1: >7}", "\n", end="")
elif n == 1:
if len(los) == 6:
print(f"{wrd1: >6}", end="")
if len(los) == 5:
print(f"{wrd1: >5}", end="")
if len(los) == 4:
print(f"{wrd1: >4}", end="")
if len(los) == 3:
print(f"{wrd1: >3}", end="")
else:
if len(los) == 6:
print(f"{wrd1: >10}", end="")
if len(los) == 5:
print(f"{wrd1: >9}", end="")
if len(los) == 4:
print(f"{wrd1: >8}", end="")
if len(los) == 3:
print(f"{wrd1: >7}", end="")
stl1 = 0
stl2 = 1
stl3 = 2
g = []
n = 0
for b in temp:
wrd1 = b[stl1]
wrd2 = b[stl2]
wrd3 = b[stl3]
n += 1
if n == len(temp):
if len(wrd1) > len(wrd3):
z = len(wrd1) - len(wrd3)
abst = " " * z
g.append(wrd2 + ' ' + abst + wrd3)
print(f"{wrd2 + ' ' + abst + wrd3 + y:>}", "\n", end="")
elif len(wrd1) == len(wrd3):
g.append(wrd2 + ' ' + wrd3)
print(f"{wrd2 + ' ' + wrd3 + y:>}", "\n", end="")
elif len(wrd1) < len(wrd3):
g.append(wrd2 + ' ' + wrd3)
print(f"{wrd2 + ' ' + wrd3 + y:>}", "\n", end="")
else:
if len(wrd1) > len(wrd3):
z = len(wrd1) - len(wrd3)
abst = " " * z
g.append(wrd2 + ' ' + abst + wrd3)
print(f"{wrd2 + ' ' + abst + wrd3 + y:>}", end="")
elif len(wrd1) == len(wrd3):
g.append(wrd2 + ' ' + wrd3)
print(f"{wrd2 + ' ' + wrd3 + y:>}", end="")
elif len(wrd1) < len(wrd3):
g.append(wrd2 + ' ' + wrd3)
print(f"{wrd2 + ' ' + wrd3 + y:>}", end="")
i = "-"
n = 0
for li in g:
lin = len(li)
n += 1
print(f"{i * lin + y:>}", end="")
print("")
tep = []
for d in arguments:
sul = eval(d)
tep.append(sul)
lst = tep
n = 0
for x, ll in zip(lst, g):
n += 1
if n == len(temp):
if len(ll) == 6:
print(f"{str(x): >10}", "\n", end="")
if len(ll) == 5:
print(f"{str(x): >9}", "\n", end="")
if len(ll) == 4:
print(f"{str(x): >8}", "\n", end="")
if len(ll) == 3:
print(f"{str(x): >7}", "\n", end="")
elif n == 1:
if len(ll) == 6:
print(f"{str(x): >6}", end="")
if len(ll) == 5:
print(f"{str(x): >5}", end="")
if len(ll) == 4:
print(f"{str(x): >4}", end="")
if len(ll) == 3:
print(f"{str(x): >3}", end="")
else:
if len(ll) == 6:
print(f"{str(x): >10}", end="")
if len(ll) == 5:
print(f"{str(x): >9}", end="")
if len(ll) == 4:
print(f"{str(x): >8}", end="")
if len(ll) == 3:
print(f"{str(x): >7}", end="")
else:
tp = []
for word in arguments:
sl = word.split()
tp.append(sl)
for _ in tp:
if len(arguments) < 6:
continue
else:
print("Error: Too many problems.", end="")
exit()
st = 0
for a in tp:
w1 = a[st]
if w1.isnumeric() is True:
continue
else:
print("Error: Numbers must only contain digits.", end="")
exit()
st3 = 2
for a in tp:
w3 = a[st3]
if w3.isnumeric() is True:
continue
else:
print("Error: Numbers must only contain digits.", end="")
exit()
st = 1
mns = "-"
pls = "+"
for a in tp:
w2 = a[st]
if w2 == mns or w2 == pls:
continue
else:
print("Error: Operator must be '+' or '-'.", end="")
exit()
st = 0
for a in tp:
w1 = a[st]
if len(w1) < 5:
continue
else:
print("Error: Numbers cannot be more than four digits.", end="")
exit()
st = 2
for a in tp:
w3 = a[st]
if len(w3) < 5:
continue
else:
print("Error: Numbers cannot be more than four digits.", end="")
exit()
temp = []
for word in arguments:
sl = word.split()
temp.append(sl)
stl1 = 0
stl2 = 1
stl3 = 2
pov = []
n = 0
for b in temp:
wrd1 = b[stl1]
wrd2 = b[stl2]
wrd3 = b[stl3]
n += 1
if n == len(temp):
if len(wrd1) > len(wrd3):
qi = len(wrd1) - len(wrd3)
abst = " " * qi
pov.append(wrd2 + ' ' + abst + wrd3)
elif len(wrd1) == len(wrd3):
pov.append(wrd2 + ' ' + wrd3)
elif len(wrd1) < len(wrd3):
pov.append(wrd2 + ' ' + wrd3)
else:
if len(wrd1) > len(wrd3):
qi = len(wrd1) - len(wrd3)
abst = " " * qi
pov.append(wrd2 + ' ' + abst + wrd3)
elif len(wrd1) == len(wrd3):
pov.append(wrd2 + ' ' + wrd3)
elif len(wrd1) < len(wrd3):
pov.append(wrd2 + ' ' + wrd3)
y = " " * 4
stl = 0
n = 0
for a, los in zip(temp, pov):
wrd1 = a[stl]
n += 1
if n == len(temp):
if len(los) == 6:
print(f"{wrd1: >10}", "\n", end="")
if len(los) == 5:
print(f"{wrd1: >9}", "\n", end="")
if len(los) == 4:
print(f"{wrd1: >8}", "\n", end="")
if len(los) == 3:
print(f"{wrd1: >7}", "\n", end="")
elif n == 1:
if len(los) == 6:
print(f"{wrd1: >6}", end="")
if len(los) == 5:
print(f"{wrd1: >5}", end="")
if len(los) == 4:
print(f"{wrd1: >4}", end="")
if len(los) == 3:
print(f"{wrd1: >3}", end="")
else:
if len(los) == 6:
print(f"{wrd1: >10}", end="")
if len(los) == 5:
print(f"{wrd1: >9}", end="")
if len(los) == 4:
print(f"{wrd1: >8}", end="")
if len(los) == 3:
print(f"{wrd1: >7}", end="")
stl1 = 0
stl2 = 1
stl3 = 2
g = []
n = 0
for b in temp:
wrd1 = b[stl1]
wrd2 = b[stl2]
wrd3 = b[stl3]
n += 1
if n == len(temp):
if len(wrd1) > len(wrd3):
z = len(wrd1) - len(wrd3)
abst = " " * z
g.append(wrd2 + ' ' + abst + wrd3)
print(f"{wrd2 + ' ' + abst + wrd3 + y:>}", "\n", end="")
elif len(wrd1) == len(wrd3):
g.append(wrd2 + ' ' + wrd3)
print(f"{wrd2 + ' ' + wrd3 + y:>}", "\n", end="")
elif len(wrd1) < len(wrd3):
g.append(wrd2 + ' ' + wrd3)
print(f"{wrd2 + ' ' + wrd3 + y:>}", "\n", end="")
else:
if len(wrd1) > len(wrd3):
z = len(wrd1) - len(wrd3)
abst = " " * z
g.append(wrd2 + ' ' + abst + wrd3)
print(f"{wrd2 + ' ' + abst + wrd3 + y:>}", end="")
elif len(wrd1) == len(wrd3):
g.append(wrd2 + ' ' + wrd3)
print(f"{wrd2 + ' ' + wrd3 + y:>}", end="")
elif len(wrd1) < len(wrd3):
g.append(wrd2 + ' ' + wrd3)
print(f"{wrd2 + ' ' + wrd3 + y:>}", end="")
i = "-"
n = 0
for li in g:
lin = len(li)
n += 1
print(f"{i * lin + y:>}", end="")