Text allign vertical and side by side

I’m currently working on a project and so far I have this.

def arithmetic_arranger(problems, val=False):
    section = []
    
    arranged_problems = ""
    #Splits value of array into new array
    for problem in problems:
        section.append(problem.split(" "))

    for test in section:   #  ["32 + 698"]
        width = max(len(test[0]), len(test[2]))
        arranged_problems = f"{test[0]:>{width+2}}\n{test[1]}{test[2]:>{width+1}}"



    # return arranged_problems

arithmetic_arranger(["32 + 698", "3801 - 2", "45 + 43", "123 + 49"])

and I want it to be like this:

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

1 Like

Thank you very much, I was struggling with it how to post it properly. I hope someone will give me answers I need.

Best regards

Sorry, I’m not a Python guy - I just wanted it readable. And now that ArielLeslie has moved it to the right subform, you should get some help.

With “for test in section” You are taking each problem separately, this will not result in one line with all first arguments (32, 3801, etc.), a second line with the operators and second arguments.
It is correct to split the problems into seperate parts (2 operands and an operator), but then they need to be combined into lines as described above.

Does this help you a little bit? Judging by your code you are able to puzzle and don’t need the answer printed here yet :wink:

1 Like

It does, someone helped me with solution, now I know what was I doing wrong. Thank you :slight_smile:

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.