如何使用python在状态机中定义最终状态
我有这个状态机:如何使用python在状态机中定义最终状态,python,state-machine,exit-code,Python,State Machine,Exit Code,我有这个状态机: class Chat(StateMachine): begin= State('begin', initial=True) state1=State('State1') state2=State('State2') go_to_state1=begin.to(state1) go_to_state2=state1.to(state2) def on_enter_begin(self): global name
class Chat(StateMachine):
begin= State('begin', initial=True)
state1=State('State1')
state2=State('State2')
go_to_state1=begin.to(state1)
go_to_state2=state1.to(state2)
def on_enter_begin(self):
global name
name = input("Please enter your name:\n")
self.go_to_state1()
def on_enter_state1(self):
global name
print("first state ")
value = input("hi "+name)
if value=="quit":
print('see you soon!')
break
else :
self.go_to_state2()
chat=Chat()
chat.on_enter_begin()
但我得到了这个:休息
^
SyntaxError:“中断”外部循环
有没有办法定义最终状态?类似于如果用户键入“退出”状态机退出/中断???是,您必须使用
返回而不是中断,因为您不在循环中:
if value=="quit":
print('see you soon!')
return True