Conditional branch to learn from Milk Boy

Introduction

I couldn't help writing it because I was struck by the fact that the repetition of "-ya-na-ka" and "-cha-ya-na-ka" was easy to incorporate into the conditional branching of programming languages (?).

Is it like this if you want to reproduce the corn flakes material?

code

class Breakfast:
    def is_sweet(self):
        return True

    def is_crunchy(self):
        return True

    def is_eaten_with_milk(self):
        return True

    def is_good_for_dinner(self):
        return True

    def is_eaten_by_monk(self):
        return True

    def exists_at_bottom_of_parfait(self):
        return True

    def is_chinese(self):
        return True

class Mother:
    def good_for_the_last_supper(self, breakfast):
        return True

    def knows_why_pentagon_is_big(self, breakfast):
        return False

    def used_to_adored(self, breakfast):
        return True

    def knows_who_to_thank(self, breakfast):
        return False

    def corn_flakes(self, breakfast):
        return False

class Father:
    def predict(self, breakfast, corn_flakes):
        if not corn_flakes:
            return "Grilled mackerel with salt"

mother = Mother()
breakfast = Breakfast()
corn_flakes = False

if breakfast.is_sweet() and breakfast.is_crunchy() and breakfast.is_eaten_with_milk():
    corn_flakes = True

if mother.good_for_the_last_supper(breakfast):
    corn_flakes = False

if not mother.knows_why_pentagon_is_big(breakfast):
    corn_flakes = True

if breakfast.is_good_for_dinner():
    corn_flakes = False

if mother.used_to_adored(breakfast):
    corn_flakes = True

if breakfast.is_eaten_by_monk():
    corn_flakes = False

if breakfast.exists_at_bottom_of_parfait():
    corn_flakes = True

if breakfast.is_chinese():
    corn_flakes = False

if not mother.knows_who_to_thank(breakfast):
    corn_flakes = True

if not mother.corn_flakes(breakfast):
    corn_flakes = False

father = Father()
print(father.predict(breakfast, corn_flakes))

Execution result

$ python milkboy.py 
Grilled mackerel with salt

Recommended Posts

Conditional branch to learn from Milk Boy
Programming to learn from books May 10
Programming to learn from books May 7
Reinforcement learning to learn from zero to deep
Sum from 1 to 10
Learn how to inflate images from TensorFlow code
MVC --Model edition to learn from 0 with prejudice only
Changes from Python 3.0 to Python 3.5
Changes from Python 2 to Python 3.0
Transition from WSL1 to WSL2
From editing to execution
Python regular expression basics and tips to learn from scratch