Write almost all test cases in my code(python 3) (Too lengthy code)


#1

def atoi(self, A):

    #A = "- 5 88C340185Q 71 8079 834617385 2898422X5297Z6900"
    #A = "-6435D56183011M11 648G1 903778065 762 75316456373673B5 334 19885 90668 8 98K X277 9846"
    #A="++7"
    #A="+954++857"
    #A = "-07041 6784513221729 1128 43144"
    #A = "V515V 5793K 627 23815945269 1 1249794L 631 8755 7"
    
    i=0
    S=""
    lis=[]
    while(i<len(A)):
        if(type(A[i])==str and A[i]!=" " and A[i]!="+" and A[i]!="-" and A[i]!="A"
        and A[i]!="B" and A[i]!="C" and A[i]!="D" and A[i]!="E" and A[i]!="F" and A[i]!="G"
        and A[i]!="H" and A[i]!="I" and A[i]!="J" and A[i]!="K" and A[i]!="L" and A[i]!="M" 
        and A[i]!="N" and A[i]!="O" and A[i]!="P" and A[i]!="Q" and A[i]!="R" and A[i]!="S" 
        and A[i]!="T" and A[i]!="U" and A[i]!="V" and A[i]!="W" and A[i]!="X" and A[i]!="Y"
        and A[i]!="Z"):
            S+=A[i]
            
        elif(A[i]==" " or A[i]=="+" or A[i]=="-" or A[i]!="A"
        or A[i]!="B" or A[i]!="C" or A[i]!="D" or A[i]!="E" or A[i]!="F" or A[i]!="G"
        or A[i]!="H" or A[i]!="I" or A[i]!="J" or A[i]!="K" or A[i]!="L" or A[i]!="M" 
        or A[i]!="N" or A[i]!="O" or A[i]!="P" or A[i]!="Q" or A[i]!="R" or A[i]!="S" 
        or A[i]!="T" or A[i]!="U" or A[i]!="V" or A[i]!="W" or A[i]!="X" or A[i]!="Y"
        or A[i]!="Z" ):
            lis.append(S)
            S=""
        i+=1
    lis.append(S) #produce list spliting around ([A,B........Z],"  ","+","-")
    #return(lis)
    if(lis[0]=='' and lis[1].isdigit()): #handle test case if first is + or -  or any alphabet
        if(A[0]=="-"):
            res=A[0]+str(int(lis[1]))
            if(int(res)<-(2**31)):
                return(-2147483648)
            else:
                return(res)
        elif(A[0]=="+"):
            res=int(lis[1])
            if(res>((2**31)-1)):
                return(2147483647)
            else:
                return(res)
        else:
            return(0)
    else:
        for i in lis:
            if(i.isdigit()==False):
                return(0)
        
            elif(i.isdigit()==True):
                if(int(i)>((2**31)-1)):
                    return(2147483647)
                
                elif(int(i)<-(2**31)):
                    return(-2147483647)
            
                else:
                    return(int(i))