Scientific Computing with Python Projects - Arithmetic Formatter

Tell us what’s happening:
Describe your issue in detail here.
Sorry to ask for help but, i am stuck. I have the correct output, but, i can not get it to pass the checker. I have redone the code many times. Any hints would be greatly appreciated.

Your code so far

def arithmetic_arranger(problems,sold = False):
    topline, operator, bottomline, solved =  ([] for i in range(4))

    if len(problems) > 5:
        print('Error: To many problems.')
        return

    for i in problems:
        p1,p2,p3 = i.split() # test split
        #try:
            #p1,p2,p3 = i.split()
        #except ValueError:
            #print('format error') # i added this, if no space between digits and operand
            #return 'format error* test'
            
        if len(p1)  > 4 or len(p3) >4:          
            return 'Error: Too many digits.'           
        elif p2 == "*" or p2 == "/": 
            return "Error: Operator must be '+' or '-'."           
        else:    
            try:
             numb1,numb3 = int(p1),int(p3)
             topline.append(p1)
             operator.append(p2)
             bottomline.append(p3)
             if p2 == "+":
                solved.append(str(int(p1)+int(p3)))
             elif p2 =='-':             
                solved.append(str(int(p1)-int(p3)))
            except ValueError:          
                return "Error: Numbers must only contain digits."
    
    b = 0
    bottom_test, bottom_dash, Top_new =  ([] for i in range(3))
    for i in bottomline:         
        dash = 0
        operator_test = operator[b]  
        if len(bottomline[b])< len(topline[b]):
            dash =(len(topline[b])-len(bottomline[b]))+1
            bottom_test.append((operator_test)+((' ')*dash)+(i))
            bottom_dash.append(("-")*len(bottom_test[b]))
            Top_new.append(("  ")+topline[b])
            dash = len(bottom_dash[b])-len(solved[b])
            solved[b]=(" "*dash)+solved[b]
        
        elif len(bottomline[b]) == len(topline[b]):
            dash = 1
            bottom_test.append((operator_test)+((' ')*dash)+(i))
            bottom_dash.append(("-")*len(bottom_test[b]))
            Top_new.append(("  "*dash)+topline[b])
            dash = len(bottom_dash[b])-len(solved[b])
            solved[b]=(" "*dash)+solved[b]        
        else:#bottom > top
            dash = 1 # changing to bottom
            bottom_test.append((operator_test)+((' ')*dash)+(i))
            bottom_dash.append(("-")*len(bottom_test[b]))
            dash =len(bottom_test[b])-len(topline[b])
            Top_new.append((" ")*dash +topline[b])
            dash = len(bottom_dash[b])-len(solved[b])
            solved[b]=(" "*dash)+solved[b]        
        b += 1

    def calc(probs):       
        ind_x = 1
        line = ""
        for prob in probs:           
            if ind_x <len(prob):            
                line = str(line +str( prob + "    "))
            else:
                line = str(line + str(prob))
            ind_x = ind_x + 1
        return line    
    top_line =calc(Top_new) 
    bot_line = calc(bottom_test)  
    dash = calc(bottom_dash)  
    solved_true =calc(solved)

    if sold:
        return (f"{top_line}\n{bot_line}\n{dash}\n{solved_true}")
    else:
        return (f"{top_line}\n{bot_line}\n{dash}")

Your browser information:
chrome
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36

Challenge: Scientific Computing with Python Projects - Arithmetic Formatter

Link to the challenge:

Thanks, I have been staring at this for a week. Thanks again,

I confused myself in my for statement so it always printed the 4 spaces at the end, thanks i finished the project. How does it save it in the replit program? i found the link. boilerplate-arithmetic-formatter (5) - Replit , will this be active for a while? i submited it. thanks

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