Created
March 15, 2016 23:43
-
-
Save otajisan/b0d6b7604302ae2b3725 to your computer and use it in GitHub Desktop.
pythonでズンドコキヨシ ref: http://qiita.com/monhan/items/b4e8b03e78c918c25fc5
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
# coding:utf-8 | |
from ZundokoKiyoshi import ZundokoKiyoshi | |
if __name__ == '__main__': | |
zundoko = ZundokoKiyoshi() | |
for i in xrange(5): | |
zundoko.check() |
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
$ python zundoko.py | |
ズン | |
ドコ | |
ズン | |
ドコ | |
ドコ | |
ズン | |
ドコ | |
ドコ | |
ズン | |
ドコ | |
ドコ | |
ズン | |
ドコ | |
ドコ | |
ズン | |
ドコ | |
ドコ | |
ズン | |
ズン | |
ズン | |
ズン | |
ドコ | |
キ・ヨ・シ! |
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
$ python execZundokoKiyoshi.py | |
ズンドコズンズンズンズンズンズンズンドコキ・ヨ・シ! | |
ズンズンズンズンドコキ・ヨ・シ! | |
ドコドコドコズンドコズンドコドコドコドコズンズンドコドコドコズンドコズンズンズンドコズンドコドコドコドコドコドコズンドコドコズンドコドコズンズンドコズンズンドコズンドコズンズンドコズンズンドコズンドコドコドコドコドコドコドコズンズンドコドコドコズンズンズンドコズンドコズンドコズンドコドコズンズンズンドコドコズンドコドコズンズンズンズンドコキ・ヨ・シ! | |
ズンズンドコズンズンドコズンズンドコズンズンズンズンドコキ・ヨ・シ! | |
ズンズンドコドコドコズンドコズンドコドコズンズンズンドコズンズンドコズンズンドコドコドコドコズンドコズンドコドコドコズンズンズンズンズンズンドコキ・ヨ・シ! |
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
# coding:utf-8 | |
from random import choice | |
ZUNDOKO_MESSAGE = 'ズンズンズンズンドコ' | |
KIYOSHI = 'キ・ヨ・シ!' | |
def zundoko(): | |
check_list = [] | |
while ''.join(check_list[-5:]) != ZUNDOKO_MESSAGE: | |
check_list.append(choice(['ズン', 'ドコ'])) | |
print check_list[-1] | |
print KIYOSHI | |
if __name__ == '__main__': | |
zundoko() |
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
# coding:utf-8 | |
from random import choice | |
class ZundokoKiyoshi: | |
CORRECT_MESSAGE = 'ズンズンズンズンドコ' | |
RESULT_MESSAGE = 'キ・ヨ・シ!' | |
_message_list = ['ズン', 'ドコ'] | |
_result = [] | |
def say_rand(self): | |
''' | |
メッセージをランダムに返す | |
''' | |
return choice(self._message_list) | |
def append(self, message): | |
''' | |
リストにメッセージを追加する | |
''' | |
self._result.append(message) | |
def empty(self): | |
''' | |
リストを空にする | |
''' | |
self._result = [] | |
def is_correct(self): | |
''' | |
リスト内のメッセージを確認し、メッセージが正しいかどうかを返す | |
''' | |
return ''.join(self._result[-5:]) == self.CORRECT_MESSAGE | |
def print_result(self): | |
''' | |
結果メッセージを返す | |
''' | |
print ''.join(self._result) + self.RESULT_MESSAGE | |
def check(self): | |
''' | |
ズンドコキヨシを実行する | |
''' | |
while (self.is_correct() is False): | |
self.append(self.say_rand()) | |
self.print_result() | |
self.empty() | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment