God i can not do formatting properly, to be precise, returning side by side results.
And i have problem with return statement and logic. inside my code on every variable i made detail comment. pls help.
def arithmetic_arranger(problems, show_solutions=True): #in variable numbers_sorted i split problems into first number, operator, and second number numbers_sorted = #this should be returned as last variable. this is problem final_product="" if len(problems) >5: 'Error: Too many problems.' #spliting problems into number1 i and number2 i and operator i for i in problems: numbers_sorted.append(i.split(" ")) for i in numbers_sorted: if i.isnumeric()==False: return "Error: Numbers must only contain digits." if i.isnumeric()==False: return "Error: Numbers must only contain digits." if i !="+" and i!="-": return "Error: Operator must be '+' or '-'." if len(i) >=5 or len(i) >=5: return "Error: Numbers cannot be more than four digits." #in results i do arimetics , first number + or minus second number result="" if i=="+": result= int(i)+int(i) elif i=="-": result= int(i)-int(i) #this is for rjust, no problem with this width = max(len(i), len(i))+2 #top line, first number and rjust top_line= i.rjust(width) #operator + second number.rjust middle_line= i +i.rjust(width-1) #this is no problem only_line="" #and final line is just number from result converted to string and r.justed so it can easly be printed final_line = str(result).rjust(width) for z in range(width): only_line +="-" #HERE ARE PROBLEMS; #first problem is that is no way how i can figure how to get results side by side..i got ok rjust, lines, #but they are printed one bellow other. pls help #second problem si -RETURN -how is this function working? when i put for example "print final product" i got what #i want.. when i want to use "return" i dont understand.. where ever i move itd, it is just prints nothing or confusion. #so how to make return to work properly, and how to format those numbers side by side.. if show_solutions: final_product= top_line +"\n" +middle_line +"\n"+only_line +"\n"+final_line print(final_product) else: final_product =top_line +"\n" +middle_line +"\n"+only_line return(final_product)