Python Forum
Take use input in sets and Dictionaries
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Take use input in sets and Dictionaries
#1
class DFA:
    current_state = None;
    def __init__(self, states, alphabet, transition_function, start_state, accept_states):
        self.states = states;
        self.alphabet = alphabet;
        self.transition_function = transition_function;
        self.start_state = start_state;
        self.accept_states = accept_states;
        self.current_state = start_state;
        return;
    
    def transition_to_state_with_input(self, input_value):
        if ((self.current_state, input_value) not in self.transition_function.keys()):
            self.current_state = None;
            return;
        self.current_state = self.transition_function[(self.current_state, input_value)];
        return;
    
    def in_accept_state(self):
        return self.current_state in accept_states;
    
    def go_to_initial_state(self):
        self.current_state = self.start_state;
        return;
    
    def run_with_input_list(self, input_list):
        self.go_to_initial_state();
        for inp in input_list:
            self.transition_to_state_with_input(inp);
            continue;
        return self.in_accept_state();
    pass;



states = {0, 1, 2, 3};
alphabet = {'a', 'b', 'c', 'd'};

tf = dict();
tf[(0, 'a')] = 1;
tf[(0, 'b')] = 2;
tf[(0, 'c')] = 3;
tf[(0, 'd')] = 0;
tf[(1, 'a')] = 1;
tf[(1, 'b')] = 2;
tf[(1, 'c')] = 3;
tf[(1, 'd')] = 0;
tf[(2, 'a')] = 1;
tf[(2, 'b')] = 2;
tf[(2, 'c')] = 3;
tf[(2, 'd')] = 0;
tf[(3, 'a')] = 1;
tf[(3, 'b')] = 2;
tf[(3, 'c')] = 3;
tf[(3, 'd')] = 0;
start_state = 0;
accept_states = {2, 3};

d = DFA(states, alphabet, tf, start_state, accept_states);

inp_program = list('abcdabcdabcd');

print (d.run_with_input_list(inp_program))
This is DFA program which takes States and Alphabets (as hard coded values) and then add them in dictionary
and for each states and alphabets we give some value to dictionary

I want to make this program user defined by
1. Takes input from user and add in set named "Set"
2. Takes input from user and add in set named "alphabets"
3 for each pair of sets and alphabets ask user to add value

Can someone help me ?

Thanks
Reply
#2
Is this a paying job?
Reply
#3
(Nov-18-2018, 09:36 AM)Larz60+ Wrote: Is this a paying job?

No this is my school assignment
Reply
#4
In that case, we'll need to see some effort from you.
What did you try to get the results you want and what problem are you facing?
Reply
#5
(Nov-18-2018, 12:30 PM)stranac Wrote: In that case, we'll need to see some effort from you.
What did you try to get the results you want and what problem are you facing?

I have tried to get input from user and add it to sets , i was succeeded but how to take user input in loop from two sets
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  create empty sets for keys in a dictionary and add values to the set naughtysensei 1 2,523 Nov-03-2020, 08:32 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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