Kellerautomat in Python

L(PDA) = {anbn | n>0}

class Stack:
    def __init__(self):
        self.stackliste = []
        self.stacklistenlaenge = 0

    def pop(self):
        if self.istLeer() == False:
            self.stacklistenlaenge = self.stacklistenlaenge - 1
            return self.stackliste.pop()

    def peek(self):
        if self.istLeer() == False:
            return self.stackliste[self.stacklistenlaenge - 1]

    def push(self, inhalt):
        self.stackliste.append(inhalt)
        self.stacklistenlaenge = self.stacklistenlaenge + 1

    def getStacklistenlaenge(self):
        return self.stacklistenlaenge

    def istLeer(self):
        if self.stacklistenlaenge <= 0:
            return True
        else:
            return False
#---------------------------------------------------
def Zustandsuebergangsfunktion(symbol):
    global state
    if state == "q0":
        if symbol == "a":
            state = "q1"
            pdaStack.pop()
            pdaStack.push("Z")
            pdaStack.push("P")
            return True
        else:
            return False
    if state == "q1":
        if symbol == "a":
            pdaStack.pop()
            pdaStack.push("P")
            pdaStack.push("P")
            state = "q1"
            return True
        elif symbol == "b":
            pdaStack.pop()
            state = "q2"
            return True
        else:
            return False
    if state == "q2":
        if symbol == "b":
            if pdaStack.peek() == "P":
                state = "q2"
                pdaStack.pop()
                if pdaStack.peek() == "Z":
                    state = "q3"
                return True
        else:
            return False
    if state == "q3":
        if pdaStack.peek() == "Z":
            pdaStack.pop()
            return True
        else:
            return False
#---------------------------------------------------
def Akzeptor(wort):
    global state
    for i in range(len(wort)):
        testsymbol = wort[i]
        aktzustand = Zustandsuebergangsfunktion(testsymbol)
        print("Zustand:     ", state, "\tAktueller Stack:  ", pdaStack.stackliste)
        if aktzustand == False:
            return False
    if pdaStack.peek() == "Z" and state == "q3":
        return True
    else:
        return False
#---------------------------------------------------

pdaStack = Stack()
pdaStack.push("Z")
state = "q0"
print("Startzustand:", state, "\tLeerzustand Stack:", pdaStack.stackliste)

ergebnis = Akzeptor("aaaaabbbbb")
print("---------\nAkzeptiert?",    ergebnis)