Skip to content

Instantly share code, notes, and snippets.

@chizuchizu
Last active December 18, 2018 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chizuchizu/9a15cc66f057583cdf0d53f94dc5942f to your computer and use it in GitHub Desktop.
Save chizuchizu/9a15cc66f057583cdf0d53f94dc5942f to your computer and use it in GitHub Desktop.
Pythonと共に百人一首で勝ちたい ref: https://qiita.com/chizuchizu/items/c5401c10682daef5a260
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