In: Computer Science
Write a program in python programming language to implement/simulate a finite automaton that accepts (only): unsigned integer numbers // 123, 007, 4567890, etc. Show: Finite Automaton Definition, Graph, Table.
if it accepts only positive integers it should reject decimals and negative numbers ar any string that is not a positive integer
following is the python code that accepts only positive integers
test_strings=['1','123','-23','45-32','546.33','123.45-','...--123','9860']
dfa = {0:{'0':1, '1':1, '2':1, '3':1, '4':1, '5':1, '6':1, '7':1,
'8':1, '9':1, '-':2, '.':2},
1:{'0':1, '1':1, '2':1, '3':1,
'4':1, '5':1, '6':1, '7':1, '8':1, '9':1, '-':2, '.':2},
2:{'0':2, '1':2,'2':2,'3':2,
'4':2, '5':2, '6':2, '7':2, '8':2, '9':2, '-':2, '.':2}}
#definition of states as dictionary
def accepts(transitions,initial,accepting,s):
state = initial
for c in s:
state =
transitions[state][c]
return state in accepting
for strings in test_strings:
print(accepts(dfa,0,{1},strings))