Zundokokiyoshi with python

Former story

Here Let's get on for the time being.

First of all, normally

zundoko.py


# coding:utf-8

from random import choice

ZUNDOKO_MESSAGE = 'Zunzunzundoko'
KIYOSHI = 'Ki yo shi!'

def zundoko():
    check_list = []
    while ''.join(check_list[-5:]) != ZUNDOKO_MESSAGE:
        check_list.append(choice(['Dung', 'Doco']))
        print check_list[-1]
    print KIYOSHI

if __name__ == '__main__':
    zundoko()

Run

$ python zundoko.py
Dung
Doco
Dung
Doco
Doco
Dung
Doco
Doco
Dung
Doco
Doco
Dung
Doco
Doco
Dung
Doco
Doco
Dung
Dung
Dung
Dung
Doco
Ki yo shi!

Umu

Classified in vain

While many people aim for a small number of bytes, they do wasteful things. Well, there are various ramblings.

ZundokoKiyoshi.py


# coding:utf-8

from random import choice

class ZundokoKiyoshi:

    CORRECT_MESSAGE = 'Zunzunzundoko'

    RESULT_MESSAGE = 'Ki yo shi!'

    _message_list = ['Dung', 'Doco']

    _result = []

    def say_rand(self):
        '''
Randomly return a message
        '''
        return choice(self._message_list)

    def append(self, message):
        '''
Add a message to the list
        '''
        self._result.append(message)

    def empty(self):
        '''
Empty the list
        '''
        self._result = []

    def is_correct(self):
        '''
Check the messages in the list and return if the message is correct
        '''
        return ''.join(self._result[-5:]) == self.CORRECT_MESSAGE

    def print_result(self):
        '''
Returns a result message
        '''
        print ''.join(self._result) + self.RESULT_MESSAGE

    def check(self):
        '''
Run Zundokokiyoshi
        '''
        while (self.is_correct() is False):
            self.append(self.say_rand())
        self.print_result()
        self.empty()
        return True

How to use

execZundokoKiyoshi.py


# coding:utf-8

from ZundokoKiyoshi import ZundokoKiyoshi

if __name__ == '__main__':
    zundoko = ZundokoKiyoshi()
    for i in xrange(5):
        zundoko.check()

Run

$ python execZundokoKiyoshi.py
Zundko ZunZunZunZunZunZunZunDokoki Yo Shi!
Zunzunzundokoki yo shi!
DoCoMo Dokodoko Zundoko Zundoko DoCoMo Dokodoko Zunzun DoCoMo Dokodoko Zundoko Zunzunzun DoCoMo Zundoko DoCoMo Dokodoko Dokodoko Zundoko DoCoMo Zundoko DoCoMo Zunzun DoCoMo Zunzun DoCoMo Zundoko Zunzun DoCoMo Zunzun DoCoMo Zundoko Dokodoko Dokodoko Dokodoko Zunzun DoCoMo Dokodoko Zunzunzun DoCoMo Zundoko Zundoko Zundoko DoCoMo Zunzunzun Dokodoko Zundoko DoCoMo Zunzunzun Zundoko Ki Yo Shi!
Zunsundoko Zunzundoko Zunzundoko Zunzundokoki!
Zunsundokodokodokodokodokozundokodokozunzundokozundokozundokodokodokodokodokodokodokodokodokodokodokozun!

My eyes are fluffy w

Recommended Posts

Zundokokiyoshi with python
Zundokokiyoshi with python / ruby / Lua
FizzBuzz with Python3
Scraping with Python
Statistics with python
Scraping with Python
Python with Go
Twilio with Python
Play with 2016-Python
Tested with Python
with syntax (Python)
Bingo with python
Zundokokiyoshi with TensorFlow
Excel with Python
Python beginner Zundokokiyoshi
Microcomputer with Python
Cast with python
Serial communication with Python
Zip, unzip with python
Django 1.11 started with Python3.6
Primality test with Python
Python with eclipse + PyDev.
Socket communication with Python
Data analysis with python 2
Scraping with Python (preparation)
Try scraping with Python.
Learning Python with ChemTHEATER 03
Sequential search with Python
"Object-oriented" learning with python
Run Python with VBA
Handling yaml with python
Solve AtCoder 167 with python
Serial communication with python
[Python] Use JSON with Python
Learning Python with ChemTHEATER 05-1
Learn Python with ChemTHEATER
1.1 Getting Started with Python
Binarization with OpenCV / Python
3. 3. AI programming with Python
Learn Zundokokiyoshi with LSTM
Kernel Method with Python
Non-blocking with Python + uWSGI
Scraping with Python + PhantomJS
Posting tweets with python
Drive WebDriver with python
Use mecab with Python3
Voice analysis with python
Think yaml with python
Operate Kinesis with Python
Getting Started with Python
Use DynamoDB with Python
Zundko getter with python
Handle Excel with python
Ohm's Law with Python
Primality test with python
Run Blender with python
Solve Sudoku with Python
Python starting with Windows 7
Heatmap with Python + matplotlib
Multi-process asynchronously with python
Python programming with Atom