Implemented Shiritori in Python

It's been a while since I posted an article. I was studying Python little by little while I wasn't publishing the article, so I feel like I've gained a sense of Python and programming.

So, I decided to make a shiritori and implemented it. In making shiritori -Take over the last letter of the previous word. = "Shiritori" ・ You cannot use words that you have already used. ・ If you end with "n", you lose. I took care to keep these three rules.

word_chain.py


hiragana_1 = "Shiritori"
used_hiragana = []
print("Shiritori start!\n", hiragana_1)

while True:
    hiragana_2 = str(input("Please put hiragana: "))
    if hiragana_2[0] != hiragana_1[-1]:
        print("The first letter is incorrect.")
        break
    elif hiragana_2 in used_hiragana:
        print("This word is already in use. You lose.")
        break
    elif hiragana_2[-1] == "Hmm":
        print("This is a word that ends with "n". You lose.")
        break
    else:
        used_hiragana.append(hiragana_1)
        used_hiragana.append(hiragana_2)
        hiragana_1 = hiragana_2
        print("It's the next turn.")

(Execution result 1)
----Shiritori start!
Shiritori
Please put hiragana:Apple
It's the next turn.
Please put hiragana:Gorilla
It's the next turn.
Please put hiragana:Swallow
The first letter is incorrect.
(Execution result 2)
----Shiritori start!
Shiritori
Please put hiragana:Risu
It's the next turn.
Please put hiragana:Grated
It's the next turn.
Please put hiragana:Risu
This word is already in use. You lose.

I omitted the execution result a little, but I was able to make a shiritori according to the three rules I mentioned at the beginning. However, this code does not contain katakana, and the drawback is that it causes trouble when using words that include lowercase letters in hiragana. I want to overcome that and improve the accuracy, but it still seems a little difficult (laughs).

Recommended Posts

Implemented Shiritori in Python
Implemented SimRank in Python
Sudoku solver implemented in Python 3
6 Ball puzzle implemented in python
Widrow-Hoff learning rules implemented in Python
Implemented label propagation method in Python
Implemented Perceptron learning rules in Python
Implemented in 1 minute! LINE Notify in Python
Quadtree in Python --2
Python in optimization
CURL in python
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Meta-analysis in Python
Unittest in python
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
Plink in Python
Constant in python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
N-gram in python
LINE-Bot [0] in Python
Disassemble in Python
Reflection in Python
Constant in python
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Quad-tree in Python
Reflection in Python
Chemistry in Python
Hashable in python
DirectLiNGAM in Python
LiNGAM in Python
Flatten in python
flatten in python
A simple HTTP client implemented in Python
Implemented in Python PRML Chapter 7 Nonlinear SVM
I implemented Cousera's logistic regression in Python
Implemented in Python PRML Chapter 5 Neural Networks
Implemented Stooge sort in Python3 (Bubble sort & Quicksort)
Implemented in Python PRML Chapter 1 Bayesian Inference
Sorted list in Python
Clustering text in Python
Daily AtCoder # 2 in Python
Implement Enigma in python
Implemented in Python PRML Chapter 3 Bayesian Linear Regression
Daily AtCoder # 6 in Python
Daily AtCoder # 18 in Python
Edit fonts in Python