Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Humza Alam

2020-310-080

ASSIGNMENT 1

state_transition = []

def q0(s,i):
    state_transition.append('q0')
    if (len(s)==i):
        return False

    if s[i] == 'a':
       return q1(s,i+1)
    else:
        return q3(s,i+1)

def q1(s,i):
    state_transition.append('q1')
    if len(s) == i:
        return False

    if s[i] == 'a' or s[i] == 'b':


        return q2(s,i+1)

def q2(s,i):
    state_transition.append('q2')
    if len(s) == i:
        return True

    if s[i] == 'a' or s[i] == 'b':


        return q2(s,i+1)

def q3(s,i):
    state_transition.append('q3')
    if len(s) == i:
        return False

    if s[i] == 'a' or s[i]  == 'b':


        return q3(s,i+1)
   
s = input("Enter string consistiong{a,b}: ")
ans = q0(s,0)
if ans:
    print("String Accepted")
Humza Alam
2020-310-080

   
    for i in state_transition:
        print(i, end = " ")
   
else:
    print("String Not Accepted")

Output:

You might also like