samedi 5 décembre 2020

If statement skipped

I have to make an FSA in python which basically means it will only take specific values of strings depending on which state it's in. I'm trying to use functions and within the function, there are if statements and for loops but it seems that the if statement in my second function is being ignored. Also when I run it on idle it asks me if I'm sure I want to kill the program. I genuinely don't know where I'm going wrong.

fsa = input("Enter string: ")


def s1():
    for i in fsa:
        if i == "A":
            print("A")
        
        
            return s2()    
        else:
            print("""False
Goodbye""")
            exit()
def s2():
        for i in fsa:
            if i=="B":
                print("B1")
                return s1()
            elif i=="C":
                print("C")
            else:
                
            
                print("Error")
                exit()
               
        
s1()
    

Aucun commentaire:

Enregistrer un commentaire