Write a Python program that implements the ‘Shiritori" (first letter. last letter) game. In this game, a person starts with a word. and the next person has to come up with a word that starts with the last letter of the previous word. (e.g.. If the first person starts with "apple", the next person has to come up with a word that starts with the letter ‘e'.)
Rules of the game:
1. Word must be a valid word.
2. Word must not have been used before.
3. Word must begin with the last letter of the previous word.
The Python program should take in an input word and check whether it exists in the database of words. If the word does not violate any rule of the game. it is deemed valid and the game continues. Else. the game ends.
The database of words would be the provided "word_list.txt" file. The program should open the "word_list.txt" file for reading, then read and store the contents of the file into a suitable Python data type.
The following illustrates what the game sessions might look like:
Please type a word: apple
Please type a word: egg
Please type a word: ear
You didn't type a word starting with '9'.
>>>
Please type a word: sun
Please type a word: new
Please type a word: won
Please type a word: new
You typed a word that has been typed before.
>>>
Please type a word: pear
Please type a word: rar
You didn't type a word found in word_list.txt.
>>>
Please make your code as clear and readable as possible. Comments to explain the workings of your code would be very much appreciated.
Rules of the game:
1. Word must be a valid word.
2. Word must not have been used before.
3. Word must begin with the last letter of the previous word.
The Python program should take in an input word and check whether it exists in the database of words. If the word does not violate any rule of the game. it is deemed valid and the game continues. Else. the game ends.
The database of words would be the provided "word_list.txt" file. The program should open the "word_list.txt" file for reading, then read and store the contents of the file into a suitable Python data type.
The following illustrates what the game sessions might look like:
Please type a word: apple
Please type a word: egg
Please type a word: ear
You didn't type a word starting with '9'.
>>>
Please type a word: sun
Please type a word: new
Please type a word: won
Please type a word: new
You typed a word that has been typed before.
>>>
Please type a word: pear
Please type a word: rar
You didn't type a word found in word_list.txt.
>>>
Please make your code as clear and readable as possible. Comments to explain the workings of your code would be very much appreciated.
If the answers is incorrect or not given, you can answer the above question in the comment box. If the answers is incorrect or not given, you can answer the above question in the comment box.