Arithmetic Arranger Project - Output Formatting

Hi everyone!

I’ve been working my way through the arithmetic arranger project and I have run up against a problem with formatting my output properly.

The applicable part of my code:

def arithmetic_arranger(strlist, answers=False):
    # create vars
    sol = None
    format = []
    output = ''
    formlist = []
    # In one loop, pull i from list, split it, answer it, format it, store it
    while True:
        #
        for i in strlist :
            # get solution
            if answers == True :
                sol = eval(i)
            format = i.split()
            a = format[0]
            b = format[1]
            c = format[2]
            d = "-"
            # generate the size of the dash line
            d = d*(2+len(a)) if len(a)>len(c) else d*(2+len(c))
            wid = len(d)
            widmid = len(d) - 1

            if answers == True :
                output = f"\n{a:>{wid}}\n{b:}{c:>{widmid}}\n{d:}\n{sol:>{wid}}\n"
                formlist.append(output)
                formlist.append("    ")
            else:
                output = f"\n{a:>{wid}}\n{b:}{c:>{widmid}}\n{d:}\n"
                formlist.append(output)
                formlist.append("    ")
        print(formlist)
        return print(" ".join(formlist))

The answers are formatted properly (I think), but they won’t print horizontally. I’ve spent hours trying to figure this out/checking stackflow and this forum, but haven’t found anything that has worked. I have a sneaking suspicion that part of the problem might be the use of \n in my fstring, but without those the formatting gets jumbled.

I’m stumped.

Any help at all would be greatly appreciated!

Thank you!!

edit: Link to my project on repl.it (sorry - first time posting here!):

please provide a link to your project so it is possible to see what the tests say, and it’s easier to debug

Done! Sorry about that!

the tests are not being called, you made it interactive for the user, but the tests are not executing

I mean, they are executing after the interactive part quits, but all fails as the functions called by the tests return None

AssertionError: None != 'Error: Too many problems.' : Expected calling "arithmetic_arranger()" with more than five problems to return "Error: Too many problems."

all the return statements in your function are just return, returning nothing

you are printing each problem separately, you need to have a single string at the end that containts all 4 problems, and return that

and returning a print statement will not return the argument of the print statement, probably just None

Oof, ya. I started working on this locally so this is the first I’ve actually put it on repl.it/run the debugger. I definitely have some work to do.

I still don’t understand why the output code/formatting isn’t working properly though (purely from a code perspective, not the debugger on repl.it).

Is there a way to have Python print horizontally when a string/list of strings has been formatted this way?

Thank you for your help!

it needs to be in a single string

multiple   other
line       stuff
stuff      on multiple
           lines

to print that you need to write

"multiple   other\nline       stuff\nstuff      on multiple\n           lines"

EDIT : This is a bit embarrassing but I just figured it out within 5 minutes of posting this. Apologies. I’m new to the forum so feel free to let me know if I should delete this or not…sorry/thanks again!

So, I took another shot at it using the one string approach. While the output works on my own terminal and in repl.it without running the debugger, it keeps getting caught up on the output tests .

It looks like it may have something to do with the number of characters in the string, but I’ve counted the spaces and compared the visual output in the README.md and it looks right…any insight would be greatly appreciated (again).

I’ve included a link to my Repl.it here again just in case.

everything seems fine:
image