Trying to solve the 'Arithmetic Formatter'

Tell us what’s happening:
Describe your issue in detail here.
Hey ! I’m new to python and I don’t understand why my code isn’t working with the tests that are made on replit.
I mean I know that there could be some errors but sometime in replit the expected output and my output are the same so I don’t get it…
Thanks if you can help and sorry for my poor level in Python
Your code so far
def arithmetic_arranger(problems, mode = False):

i = 0

arranged_problems = ""

data = []

response = []

if len(problems) > 5:

    print('Error: Too many problems.')

    return

for values in problems :

    data.append(re.findall(r"\S+", values))

for values in data :

    if values[1] != "+" and values[1] != "-":

        print('Error: Operator must be '+' or '-'.')

        return

    try:

        int(values[0])

        int(values[2])

    except:

        print('Error: Numbers must only contain digits.')

        return

    if len(values[0]) > 4 or len(values[0]) > 4:

        print('Error: Numbers cannot be more than four digits.')

        return

    if len(values[0]) >= len(values[2]) :

        response.append(["  "+values[0], values[1], " "+" "*(len(values[0])-len(values[2]))+values[2], len(values[0])+2])

    else :

        response.append(["  "+" "*(len(values[2])-len(values[0]))+values[0], values[1], " "+values[2], len(values[2]) +2])

while i<= 3:

    for values in response :

        if i == 0:

            arranged_problems += values[i]

            if response.index(values) != len(response):

                arranged_problems += "    "

        elif i == 1:

            arranged_problems += values[i]+values[i+1]

            if response.index(values) != len(response):

                arranged_problems += "    "

        elif i == 3:

            arranged_problems += '-'*values[i]

            if response.index(values) != len(response):

                arranged_problems += "    "

    if i == 0 or i == 1:

        arranged_problems += '\n'

    if i == 3 and mode == True:

        arranged_problems += '\n'

    i+=1

if mode == True:

    for values in response:

        if values[1] == "+":

            arranged_problems += " "*(values[3] - len(str(int(values[0])+int(values[2])))) + str(int(values[0])+int(values[2]))

        else :

            arranged_problems += " "*(values[3] - len(str(int(values[0])+int(values[2])))) + str(int(values[0])-int(values[2]))

        if response.index(values) != len(response):

            arranged_problems += "    "

return arranged_problems

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:92.0) Gecko/20100101 Firefox/92.0

Challenge: Arithmetic Formatter

Link to the challenge:

What errors are you getting?

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