Skip to content

Instantly share code, notes, and snippets.

@rsayers
Created May 9, 2022 14:12
Show Gist options
  • Save rsayers/46bebb3309c8ccdfdc2a62be258799de to your computer and use it in GitHub Desktop.
Save rsayers/46bebb3309c8ccdfdc2a62be258799de to your computer and use it in GitHub Desktop.
Simple terminal quiz game to learn the Yamnote Line stops and their Kanji
import random
stations = {}
stations["Shinagawa"] = "品川"
stations["Ōsaki"]="大崎"
stations["Gotanda"]="五反田"
stations["Meguro"]="目黒"
stations["Ebisu"]="恵比寿"
stations["Shibuya"]="渋谷"
stations["Harajuku"]="原宿"
stations["Yoyogi"]="代々木"
stations["Shinjuku"]="新宿"
stations["Shin-Ōkubo"]="新大久保"
stations["Takadanobaba"]="高田馬場"
stations["Mejiro"]="目白"
stations["Ikebukuro"]="池袋"
stations["Ōtsuka"]="大塚"
stations["Sugamo"]="巣鴨"
stations["Komagome"]="駒込"
stations["Tabata"]="田端"
stations["Nishi-Nippori"]="西日暮里"
stations["Nippori"]="日暮里"
stations["Uguisudani"]="鶯谷"
stations["Ueno"]="上野"
stations["Okachimachi"]="御徒町"
stations["Akihabara"]="秋葉原"
stations["Kanda"]="神田"
stations["Tokyo"]="東京"
stations["Yūrakuchō"]="有楽町"
stations["Shimbashi"]="新橋"
stations["Hamamatsuchō"]="浜松町"
stations["Tamachi"]="田町"
stations["Takanawa Gateway"]="高輪ゲートウェイ"
class StationGame:
def __init__(self):
self.total = 0
self.correct = 0
self.wrong = 0
while True:
self.run()
def run(self):
self.total += 1
keys = list(stations.keys())
a = random.choice(keys)
keys.remove(a)
others = random.choices(keys, k=3)
print(f"What station is? {stations.get(a)}?")
grp = [a] + others
random.shuffle(grp)
i = 1
for g in grp:
print(f"\t {i}. {g}")
i += 1
while True:
c = input('Choice? ')
if c:
c = c.strip()
else:
continue
c = int(c)
if grp[c-1] == a:
self.correct += 1
print("Correct")
else:
self.wrong += 1
print(f"The correct answer is {a}")
break
status = f"Total: {self.total} Correct: {self.correct} Wrong: {self.wrong}"
print(status)
print("-"*(len(status)))
StationGame()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment