1. Implement your data representation in your chosen language. 2. Write a program that implements the DFA from Figure 1.4 of the textbook as an instance of the DFA data representation that you have chosen. This program must also respond to the following stdin inputs as follows: o states: print out the states, one per line, in no particular order o alpha: print out the alphabet, one char per line, in no particular order o transitions: print out, in no particular order, each possible transition on its own line: "from" state first, followed by input char, followed by "to" state, with a space separating each. o start: print out the start state, on its own line o accepts: print out the accept states, one per line, in no particular order
Please help me in this python code get me output of it and resolve error if posible i posted pictures of my question for your help
import sys
def main():
transition = [[[0,1],[0]], [[4],[2]], [[4],[3]], [[4],[4]]]
input = raw_input("enter the string:")
input = list(input) #copy the input in list because python strings are immutable and thus can't be changed directly
for index in range(len(input)): #parse the string of a,b in 0,1 for simplicity
if input[index]=='a':
input[index]='0'
else:
input[index]='1'
final = "3" #set of final states = {3}
start = 0
trans(transition, input, final, start)
print ("rejected")
def trans(transition, input, final, state):
for each in transition[state][int(input[0])]: #check for each possibility
if each < 4: #move further only if you are at non-hypothetical state
state = each
if len(input)==1:
if (str(state) in final): #last symbol is read and current state lies in the set of final states
print ("accepted")
sys.exit()
else:
continue
trans(transition, input[1:], final, state) #input string for next transition is input[i+1:]
main()
![2. Write up an informal description of your chosen representation in a section of your
README, labeled DFA Data Representation.
For example, here's mine in Racket:
DFA Data Representation:
A State is a string
A Symbol is a 1-char string
A DFA is a (struct states alpha delta start accepts)
where:
- states is a list of State
- alpha is a list of Symbol
- delta is a hash of State Symbol -> Symbol
- start is a State
- accept is a list of State
-
Note that structs, strings, lists, and hashes are data structures in my language. Your
data representation will vary depending on your chosen language and the available
constructs in that language. For example, if you're using Java, you might choose an
Object instead of a struct.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fe38e6c97-118a-4b3e-ba11-5c7bbd7d520d%2F7f7e094f-9c3a-426a-aaaa-b917c573b4cf%2Ftwseok_processed.png&w=3840&q=75)
![1. Implement your data representation in your chosen language.
2. Write a program that implements the DFA from Figure 1.4 of the textbook as an
instance of the DFA data representation that you have chosen. This program must also
respond to the following stdin inputs as follows:
o states: print out the states, one per line, in no particular order
o alpha: print out the alphabet, one char per line, in no particular order
o transitions: print out, in no particular order, each possible transition on its own
line: "from" state first, followed by input char, followed by "to" state, with a space
separating each.
o start: print out the start state, on its own line
o accepts: print out the accept states, one per line, in no particular order
1
92
93
0,1
FIGURE
1.4
A finite automaton called M1 that has three states](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fe38e6c97-118a-4b3e-ba11-5c7bbd7d520d%2F7f7e094f-9c3a-426a-aaaa-b917c573b4cf%2Fpjj8kzo_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)