Why dont print like it must?

Tell us what’s happening:
arithmetic_arranger i have pass the firts five test but the six one give me error but i encapsulete and try it and the resulst are well printed

Your code so far

def arithmetic_arranger(problems, responder=False):
    nums = ''
    dens = ''
    sums = ''
    respuestas = ""
    if len(problems) > 5:
        return 'Error: Too many problems.'
    for k in problems:
        l = (k.split(' '))
        num = l[0]
        op = l[1]
        den = l[2] 
        if len(num) > 4 or len(den) > 4:
            return 'Error: Numbers cannot be more than four digits.'
        if not num.isnumeric() or not den.isnumeric():
            return 'Error: Numbers must only contain digits.'
        if op == '+' or op == '-':
            length = max(len(num), len(den)) + 2
            top = str(num).rjust(length)
            bottom = op + str(den).rjust(length - 1)
            sum = ''
            for s in range(length):
                sum += '-'
            nums += top + '    '
            dens += bottom + '    '
            sums += sum + '    '
        else:
            return "Error: Operator must be '+' or '-'."
    nums = nums.rstrip()
    dens = dens.rstrip()
    sums = sums.rstrip()
    if responder:
        for k in problems:
          l = (k.split(' '))
          num = l[0]
          op = l[1]
          den = l[2]
          respuesta = ""
          if op == "+" :
            respuesta = (int(num) + int(den))
          else:
            respuesta = (int(num) - int(den))   
          length = max(len(num), len(den)) + 2
          top = str(respuesta).rjust(length)
          respuestas += top + '    ' 
          respuestas.rstrip()
          arranged_problems = nums + '\n' + dens + '\n' + sums + "\n" + respuestas
        return(arranged_problems)
    else:    
        arranged_problems = nums + '\n' + dens + '\n' + sums 
        return (arranged_problems)

Your browser information:

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

Challenge: Arithmetic Formatter

Link to the challenge:

can you please share your repl?

It may be that you are printing whitespace " " at the end of each line that it was not expecting.
I had a similar problem and this was my solution, might want to try it out

EDIT: Nevermind, saw the .rstrip()

sorry the format i dont have a image editor instaled and for take to long to answer i also work while estudy so time is short XD

You were asked to provide a link to the project on repl.it, not a screenshot.

1 Like

have you also added the results? that is not expected

I don’t understand what you mean when you say that the results are only shown in the last test and that’s where you have to give them back, right? And the last test says it’s not the same, but it is, it can be more specific. I am very newbie to this python, it is the first language I learn.