samedi 30 mai 2020

State machine with python

hi I am trying to create a state machine that change state with regards to the input of the user. if the user types "A" the state machine is on StateA else on StateB. this is what I did but I can't finish it.

from statemachine import StateMachine, State

value=''

class Chat(StateMachine):

    begin= State('begin', initial=True)
    StateA=State('A')
    StateB=State('B')

    go_to_A=begin.to(StateA)
    go_to_B=begin.to(StateB)


    def on_enter_begin(self):
        global value
        value = input("Please enter a string:\n")
        if value=="A":
            go_to_A() # I want to know how can I execute this transition 
        else :
            go_to_B() # else this transition 


chat=Chat()
chat.current_state
chat.go_to_A()
chat.current_state

Aucun commentaire:

Enregistrer un commentaire