def arithmetic_arranger(numbers,option=False):
final = []
testedevet = ""
if(len(numbers) > 5):
return "Error: Too many problems."
if any("x" in s for s in numbers):
return "Error: Operator must be '+' or '-'."
if any("/" in s for s in numbers):
return "Error: Operator must be '+' or '-'."
for items in numbers:
item = items.split()
valorloco = (item[0].isnumeric()) & (item[2].isnumeric())
if(not(valorloco)):
return "Error: Numbers must only contain digits."
if ((len(item[0]) > 4) | (len(item[2]) > 4)):
return "Error: Numbers cannot be more than four digits."
else:
if(option == True):
n1 = int(item[0])
op = item[1]
n2 = int(item[2])
if(op == '+'):
result = n1 + n2
else:
result = n1 - n2
if(n1>n2):
maior = n1
else:
maior = n2
maior = str(maior)
traco = "-" * (len(maior) + 2)
line_new = '{:>{n1len}}\n{:>0} {:>{n2len}}\n{:>0}\n{:>{n1len}}'.format(n1,op,n2,traco,result,n1len = len(maior) + 2, n2len = len(maior))
final.append(line_new)
testedevet = testedevet + line_new
else:
n1 = int(item[0])
op = item[1]
n2 = int(item[2])
if(op == '+'):
result = n1 + n2
else:
result = n1 - n2
if(n1>n2):
maior = n1
else:
maior = n2
maior = str(maior)
traco = "-" * (len(maior) + 2)
line_new = '{:>{n1len}}\n{:>0} {:>{n2len}}\n{:>0}\n'.format(n1,op,n2,traco,n1len = len(maior) + 2, n2len = len(maior))
final.append(line_new)
(arithmetic_arranger(["32 + 8", "1 - 3801", "9999 + 9999", "523 - 49"],True))
I need help to fix the output, just the first position of each element in array is changing
32
+ 8
----
40 1
- 3801
------
-3800 9999
+ 9999
------
19998 523
- 49
-----
474