Created
December 18, 2018 08:31
-
-
Save chizuchizu/c67a75b107cc502c43c1fb04b2d290e6 to your computer and use it in GitHub Desktop.
百人一首の練習
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import pandas as pd | |
def load(): | |
return pd.read_csv("百人一首.csv") | |
def loop(simo, kami): | |
while True: | |
n = random.randint(0, 99) # 詠む番号を決める | |
i = 0 | |
while True: | |
j = 1 | |
simo_n = simo[n] | |
kami_n = kami[n] | |
print("【", j, "問目】下の句は", simo_n, "\n") | |
s = input() | |
if s == "end": # endは終了 | |
break | |
if kami_n == s: # 正解ならもう次のループ | |
print("正解です!\n") | |
break | |
else: | |
print("不正解です…") | |
while i < 3: | |
print("後2回チャンスを与えます") | |
if len(kami_n) != 1: | |
print("上の句の一文字目は", kami_n[0]) | |
s = input() | |
if s == "end": | |
break | |
if kami_n == s: | |
print("正解です") | |
break | |
else: | |
print("不正解です") | |
if i == 2: | |
print("正解は", kami_n) | |
i += 1 | |
break | |
j += 1 | |
if s == "end": | |
break | |
def main(): | |
df = load() # データの読み込み | |
kami = df["上"] | |
simo = df["下"] | |
# ルール説明 | |
print("【チズチズの決まり字特訓】\n") | |
print("【ルール】") | |
print("下の句(決まり字)を詠むので、上の句の決まり字を答えて下さい。") | |
print("辞めたかったら「end」って言ってね!\n") | |
loop(simo, kami) | |
if __name__ == "__main__": | |
main() # 実行 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment