Question: The answer MUST be code and not a description explaining the question, Question 1 ( A Simple DFA ) Implement the DFA below in Python,
The answer MUST be code and not a description explaining the question,
Question A Simple DFA Implement the DFA below in Python, push your code to gitlab.
Notes:
The alphabet is
Your implementation should follow the definition of this DFA only, regardless of its capability to
capture valid arithmetic expressions in real life
Please use the following template:
import os
class DFA:def initself:
def resetself:
def transitionself char:
def isvalidself string:def processstringself inputstring:self.reset
for char in inputstring:
self.transitionchar
if self.state 'invalid':
return False
return self.isaccepting
def main:
for i in range:
filename f'test i:dtxt
if ospath.isfilefilename:
with openfilename, r as file:
inputstring file.readstrip
dfa DFA
if dfa.processstringinputstring:
printffilename: Valid"
else:
printffilename : Invalid"
else:
printffilename: File not found"
if :
main
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
