Python Forum
Need urgent help in this question of Automata Programming Paradigm
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need urgent help in this question of Automata Programming Paradigm
#1
The question is; Write a deterministic automata code for the language with ∑ = {0, 1} accepts the only input 101.

My classmate sent the following code but it doesnt seem to work. PLEASE HELP.

Code:
from automata.fa.dfa import DFA
dfa=DFA(
  states={'q0','q1','q2','q3'},
  inputs symbols={'0','1'},
  transitions={
  'q0':{'0':'q0','1':'q1'}
  'q1':{'0':'q2','1':'q1'}
  'q2':{'0':'q2','1':'q3'}
  'q3':{'0':'q3','1':'q3'}
  },
  initial state='q0',
  final state={'q3'}
)
dfa.read_input('101') #answer is '101'
dfa.read_input('010') #answer is 'error'
if dfa.accepts_inputs('101'):
   print('accepted')
else:
   print('rejected')
Reply
#2
What doesn't work. Does it give the wrong output or does it report an error and quit? If an error, pleas post the entire error message, including any traceback.

dfa.read_input('101') should return 'q3'
dfa.read_input('010') should return 'q2'

You should tell your friend the transitions map is incorrect. I am pretty sure it would accept '0101' or '1101' or '1011010101' or many other combinations.

To test your solution you need more test cases. I think you would learn quite a lot from using read_input_stepwise.
Reply
#3
(Apr-27-2020, 05:48 PM)deanhystad Wrote: What doesn't work. Does it give the wrong output or does it report an error and quit? If an error, pleas post the entire error message, including any traceback.

I edited the code a bit.
from automata.fa.dfa 
import DFA
dfa=DFA(
    states={'q0','q1','q2','q3'},
    inputs_symbols= {'0','1'},
    transitions={
    'q0':{'0':'q0','1':'q1'},
    'q1':{'0':'q2','1':'q1'},
    'q2':{'0':'q2','1':'q3'},
    'q3':{'0':'q3','1':'q3'}
    },
    initial_state='q0',
    final_state={'q3'}
    )
dfa.read_input('101') #answer is '101'
dfa.read_input('010') #answer is 'error'
if dfa.accepts_inputs('101'):
    print('accepted')
else:
    print('rejected')
The following is the error:
File "<ipython-input-1-427c1524b6c1>", line 1
from automata.fa.dfa
^
SyntaxError: invalid syntax
Reply
#4
you cannot split from automata.fa.dfa import DFA on 2 lines.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
(Apr-27-2020, 05:56 PM)buran Wrote: you cannot split from automata.fa.dfa import DFA on 2 lines.

Still doesn't work. I am really new to python and coding.
This is the error:

ModuleNotFoundError Traceback (most recent call last)
<ipython-input-2-d35aa8898687> in <module>
----> 1 from automata.fa.dfa import DFA
2 dfa=DFA(
3 states={'q0','q1','q2','q3'},
4 inputs_symbols= {'0','1'},
5 transitions={

ModuleNotFoundError: No module named 'automata'
Reply
#6
probably that package
https://pypi.org/project/automata-lib/
https://github.com/caleb531/automata
did you install it?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Exclamation Python Homework (Urgent help needed!!) chickenseizuresalad 6 4,265 Oct-11-2021, 01:59 AM
Last Post: Underscore
Exclamation urgent , Python homework alm 2 2,290 May-09-2021, 11:19 AM
Last Post: Yoriz
  urgent I got a syntax errors alm 2 5,837 Feb-28-2021, 02:54 PM
Last Post: alm
Heart Urgent homework help needed Medou 4 2,704 Nov-24-2020, 09:28 AM
Last Post: buran
  Programming Question anon47820 1 1,864 Jun-30-2020, 07:50 PM
Last Post: Yoriz
  [Urgent] build code GodMaster 2 1,792 Mar-23-2020, 12:25 AM
Last Post: jefsummers
  Bifid Genkey (Urgent) Laura123 2 2,035 Mar-09-2020, 08:09 PM
Last Post: micseydel
  Python Homework Help *Urgent GS31 2 2,571 Nov-24-2019, 01:41 PM
Last Post: ichabod801
  Verilog HDL Programming to Python Programming? noobcoder 1 3,027 Jul-18-2019, 09:28 PM
Last Post: nilamo
  Need help! Please! Urgent! foxylen 1 2,287 Feb-27-2019, 05:50 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020