A very simple code..., yet I can't find the error ¿¡

Viewed 33

Whenever I run this code to reorganize equations vertically, a syntax error happens in line 23, yet I don't know why.

def arithmetic_arranger(x):
    num1 = list()
    oper = list()
    num2 = list()
    unli = list()
    int1 = list()
    int2 = list()     
    
    if len(x) > 4:
        print("Error: Too many problems.")
        return 
    for i in x:
        try:
            a, b, c = i.split()
        except:
            print("Error: The equation must contain one operator between two numbers.")
            return
        if len(a) > 4 or len(c) > 4:
            print("Error: Numbers cannot be more than four digits.")
            return
        if c != "+" or c != "-":
            print("Error: The operator must be '+' or '-'."
            return    # line 23                 
        try:
            int1.append(int(a))
            int2.append(int(c))
        except:
            print("Error: Numbers must only contain digits.")
            return
        
        while len(a) < len(c):
            a == " " + a
        while len(c) < len(a):
            c == " " + c
            
        num1.append(a)
        num2.append(c)
        oper.append(b + " ")
        unli.append("-" * a + "--")
        
    print("  " + num1[0] + "      " + num1[1] + "      " + num1[2] + "      " + num1[3])
    print(oper[0] + num2[0] + "    " + oper[1] + num2[1] + "    " + oper[2] + num2[2] + "    " + oper[3] + num2[3])
    print(unli[0] + "    " + unli[1] + "    " + unli[2] + "    " + unli[3])


arithmetic_arranger(["567 + 45", "716 - 6378", "77 + 120", "9999 - 8888")

I've tried it in another code editors and they show the same error every time. Any ideas?

0 Answers
Related