Don't really understand how they want me to code it

Tell us what’s happening:
So I am working on Scientific Computing with Python Projects - Arithmetic Formatter
and here is the criteria

Create a function that receives a list of strings that are arithmetic problems and returns the problems arranged vertically and side-by-side. The function should optionally take a second argument. When the second argument is set to True , the answers should be displayed.

Constraints:

  1. Limit to 5 problems max for each input or else it will print
    “Error: too many problems”

  2. Addition and Subtraction only

  3. Each operand should only be digits

  4. Operand as at most 4 digits

So I am using pycharms and according to the criteria it satisfies all the constraints and this is my code:

Your code so far

        def arithmetic_arranger(alist, *args):
    alen = len(alist)
    if (alen > 5):
        return "Error: Too many problems."

    firstline = ""
    secondline = ""
    tline = ""
    lastline = ""

    for x in alist:

        checker = x.count("*")
        checker2 = x.count("/")

        if checker | checker2 > 0:
            return "Error: Operator msut be '+' or '-'."

        txt = x.split(" ")
        plen = max(len(txt[0]), len(txt[2]))

        if plen > 4:
            return "Error: Numbers cannot be more than four digits."

        if txt[0].isdigit() & txt[2].isdigit():

            if (plen == len(txt[0])):

                fline = "  " + txt[0] + "   "
                firstline = firstline + fline

                diff = len(txt[0]) - len(txt[2]) + 1
                dspace = " " * diff

                sline = txt[1] + dspace + txt[2] + "   "

                secondline = secondline + sline

                tl = (plen + 2) * "_" + "   "
                tline = tline + tl

                if txt[1] == "+":
                    a1 = int(txt[0])
                    a2 = int(txt[2])
                    addlines = a1 + a2

                    ss2 = str(addlines)


                    a3 = len(tl) - 3 - len(ss2)

                    ss3 = " " * a3
                    ss2 = ss3 + ss2 + "   "

                    lastline = lastline + ss2

                else:
                    s1 = int(txt[0])
                    s2 = int(txt[2])
                    sublines = s1 - s2

                    ss2 = str(sublines)

                    s3 = len(tl) - 3 - len(ss2)
                    ss3 = s3 * " "
                    ss2 = ss3 + ss2 + "   "

                    lastline = lastline + ss2


            else:
                diff = len(txt[2]) - len(txt[0]) + 2
                dspace = " " * diff

                fline = dspace + txt[0] + "   "
                firstline = firstline + fline

                sline = txt[1] + " " + txt[2] + "   "
                secondline = secondline + sline

                tl = (plen + 2) * "_" + "   "
                tline = tline + tl

                if txt[1] == "+":
                    a1 = int(txt[0])
                    a2 = int(txt[2])
                    addlines = a1 + a2
                    ss2 = str(addlines)

                    a3 = len(tl) - 3 - len(ss2)

                    ss3 = " " * a3
                    ss2 = ss3 + ss2 + "   "
                    lastline = lastline + ss2

                else:
                    s1 = int(txt[0])
                    s2 = int(txt[2])

                    sublines = s1 - s2
                    ss2 = str(sublines)
                    s3 = len(tl) - 3 - len(ss2)
                    ss3 = s3 * " "
                    ss2 = ss3 + ss2 + "   "
                    lastline = lastline + ss2

        else:
            return "Error: Numbers must only contain digits"

    if args:
        arr = [firstline, secondline, tline, lastline]
        for x in arr:
            print(x)
    else:
        arr = [firstline, secondline, tline]
        for x in arr:
            print(x)

Your browser information:

On my pycharms ide it runs perfectly fine with no errors but when i copy and paste it on the webpage it keeps running into errors

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36.

Challenge: Arithmetic Formatter

Link to the challenge:

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 (’).

So what is the error you are getting?

That’s the real question

A post was split to a new topic: Python artithmetic formatter