#
# Simple state machine example using python 3
#
# Marc Groenewegen, May 2020

# possible states: INIT EXIT SINE SAW

import sys

state = "INIT"


def determineNewState(command):

  global state

  # if user indicates 'quit' or 'exit', always go to exit state
  if command == "quit" or command == 'exit':
    state="EXIT"

  if state == "INIT":
    if command == "sine":
      state="SINE"
    if command == "saw":
      state="SAW"

  if state == "SINE":
    if command == "saw":
      state="SAW"

  if state == "SAW":
    if command == "sine":
      state="SINE"

  if state == "EXIT":
    print("Program ends here")
    sys.exit()

  return state


while True:
    command = input("Give command -> ") # ask for input
    newState = determineNewState(command)
    print("The state is now " + newState)

