Question: Starter code: def get_ch(): # prompt for the input in a loop ch = input(Enter a character or press the Return key to finish: )




Starter code:
def get_ch(): # prompt for the input in a loop ch = input("Enter a character or press the Return key to finish: ") # in case of invalid input, print the following error message print("Invalid input, please try again.") # return the ch at the end def find_state(state, ch): pass def main(): print("I can recognize if you are laughing or not.") print("Please enter one character at a time.") # initialize the variables, for example: string = "" # call the functions in a loop # when user enters an empty string, you should print the results print(" You entered", string) print("You are laughing.") print("You are not laughing.") main() Language: Python Program used: PyCharm Interpreter: 3.6.1 at /anaconda/bin/python Background Finite State Machine or FSM is also called Finite State Automata. A Finite State Machine is a popular tool that is widely used in computer science. Why it is so popular? Because it is simple, and casy to understand and implement. Here is a brief introduction: http://cs.union.edu/-striegnk/courseslp-with-prolog/htmlode2.html Your task is to implement an FSM that can recognize simple patterns of strings such as: ha! haha! hahaha! ho! hoho! hohoho! hahohoho hahohahoha! Basically, the pattern to be recognized is a sequence of "ha" or "ho", or a mixture of both. The sequence can be of any length (at least greater than three, i.e., the shortest sequence is "ha!" or "ho!"). There is no restriction on how many "ha"s or "ho"s the sequence can contain, and the "ha"s and "ho"s can appear in any order if the sequence is a mixture of both. The string must end with one m The FSM that recognizes those exact string patterns can be drawn as follows: a,o start here succes all characters all other characters 5failure all characters This FSM has 5 states and 9 transitions. State 1 is the start state and state 4 is the successful end state while state 5 is the unsuccessful end state. The transitions indicate how one transits from one state to another. For example, if we are at state 1 (start state) and observe an "h", then we transit to state 2, but if we observe any other character we transition to state 5 (failure). Notice that if we land in state 5, any other character will transition us back into state 5,i.e. once in state 5 we never leave When using this FSM to recognize a string pattern (i.e., whether or not an input string conforms to the pattern Language: Python Program used: PyCharm Interpreter: 3.6.1 at /anaconda/bin/python Background Finite State Machine or FSM is also called Finite State Automata. A Finite State Machine is a popular tool that is widely used in computer science. Why it is so popular? Because it is simple, and casy to understand and implement. Here is a brief introduction: http://cs.union.edu/-striegnk/courseslp-with-prolog/htmlode2.html Your task is to implement an FSM that can recognize simple patterns of strings such as: ha! haha! hahaha! ho! hoho! hohoho! hahohoho hahohahoha! Basically, the pattern to be recognized is a sequence of "ha" or "ho", or a mixture of both. The sequence can be of any length (at least greater than three, i.e., the shortest sequence is "ha!" or "ho!"). There is no restriction on how many "ha"s or "ho"s the sequence can contain, and the "ha"s and "ho"s can appear in any order if the sequence is a mixture of both. The string must end with one m The FSM that recognizes those exact string patterns can be drawn as follows: a,o start here succes all characters all other characters 5failure all characters This FSM has 5 states and 9 transitions. State 1 is the start state and state 4 is the successful end state while state 5 is the unsuccessful end state. The transitions indicate how one transits from one state to another. For example, if we are at state 1 (start state) and observe an "h", then we transit to state 2, but if we observe any other character we transition to state 5 (failure). Notice that if we land in state 5, any other character will transition us back into state 5,i.e. once in state 5 we never leave When using this FSM to recognize a string pattern (i.e., whether or not an input string conforms to the pattern
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
