Tell us what’s happening:
This is my project Arithmetic Formatter
All the requirements are functional but it doesn’t seem to pass the test on repl.it
I’d like to know how to print those problems horizontally, please?
And if someone can tell me why it failed the test please ?
Your code so far
import re
def arithmetic_arranger(problems,answer=False):
counter=0
for operations in problems :
counter+=1
op = re.findall(r"\+|\-|\*|\/",operations)[0]
at = "".join(operations.replace(op,'').split())
if at.isdigit():
if op=="+" or op=="-":
a=re.findall(r"\d+",operations)[0]
b=re.findall(r"\d+",operations)[1]
x=int(a)
y=int(b)
f_result=x+y
s_result=x-y
if len(a) < 5 and len(b) < 5:
if len(a) > len(b):
term_sec= op+' '+' '*(len(a)-len(b))+b
else:
term_sec= op+' '+b
lon=len(term_sec)
pos='{:>'+str(lon)+'}'
p = pos.format(a)+'\n'+pos.format(term_sec)+'\n'+'-'*lon
if counter <6:
if answer==False:
print(p)
print('\n')
else:
if op=="+":
print(p)
print(pos.format(f_result))
print('\n')
elif op=="-":
print(p)
print(pos.format(s_result))
print('\n')
else:
print("Error: Too many problems.")
else:
print("Error: Numbers cannot be more than four digits.\n")
else:
print("Error: Operator must be '+' or '-'.\n")
else:
print("Error: Numbers must only contain digits.\n")
arithmetic_arranger(["13 + 1","23+ 456342","34445 + 344445","123 + 23","34+55","456-678"],True)
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36
.
Challenge: Arithmetic Formatter
Link to the challenge: