Hello, can anyone help, when I run code all the conditions were ok, but in test I got 10/10 Fails which I don’t understand
Here is the code
def arithmetic_arranger (problems, second_arg = False):
firstnum =[];
secondnum =[];
operator =[];
rez =[]
problem =[]
for x in problems:
problem.append(x.lstrip().rstrip().split(" "))
if len(problems)>5:
aranged_problems_error = "Error: Too many problems"
return (aranged_problems_error)
for x in problem:
try:
firstnum.append(int(x[0]))
secondnum.append(int(x[2]))
operator.append(x[1])
except :
aranged_problems_error = "Error: Numbers must only contain digits. "
return (aranged_problems_error)
if ((x[1]) == "*" or (x[1]) == "/"):
aranged_problems_error = "Error: Operator must be '+' or '-'. "
return (aranged_problems_error)
for x in range(len(firstnum)):
if (len(str(firstnum[x]))>4 or len(str(secondnum[x]))>4):
aranged_problems_error = "Error: Numbers cannot be more than four digits. "
return (aranged_problems_error)
first_row =""
second_row =""
lines =""
third_row=""
aranged_problems =""
for x in range(len(operator)):
b = len(str(max(firstnum[x], secondnum[x])))
c= (str(firstnum[x]).rjust(b+2, " "), " "*4)
first_row +="".join(c)
for x in range(len(operator)):
b = len(str(max(firstnum[x], secondnum[x])))
c= (str(operator[x]).ljust(1," "), str(secondnum[x]).rjust(b+1, " ")," "*4)
second_row +="".join(c)
for x in range(len(operator)):
b = len(str(max(firstnum[x], secondnum[x])))
c= (str("-"*(b+2)).rjust(b), " "*4)
lines +="".join(c)
aranged_problems = (first_row + "\n" + second_row + "\n" + lines)
if second_arg == True:
for x in range(len(operator)):
if (operator[x]== "+"):
rez.append(firstnum[x] + secondnum[x])
else:
rez.append(firstnum[x] - secondnum[x])
for x in range(len(operator)):
b = len(str(max(firstnum[x], secondnum[x])))
c= (str(rez[x]).rjust(b+2, " ")," "*4)
third_row +="".join(c)
aranged_problems = (first_row + "\n" + second_row + "\n" + lines + "\n" + third_row)
return (aranged_problems)
else:
return (aranged_problems)