Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
1
Help us understand the problem. What is going on with this article?
@roadricefield

はちみーのうたオートマトン書いてみた

こんにちは!バイオインフォマティクス系オタク会社員のroadricefieldです!今日はGW暇なので以下の𝐴𝑣𝑒𝑛𝑡𝑎𝑑𝑜𝑟さんのTweetのトーカイテイオーの「はちみーのうた」オートマトンをPythonで書いてみました.

import sys

class AutoUmaton:
    kashi = ["はちみー", "をなめるとー", "あしがー", "はやくーなる"]
    state = 0
    def transition(self, ip):
        print(self.kashi[self.state])
        if self.state == 0:
            if(ip):
                self.state = 1
            else:
                pass
        elif self.state == 1:
            if(ip):
                self.state = 0
            else:
                self.state = 2
        elif self.state == 2:
            if(ip):
                self.state = 3
            else:
                pass
        elif self.state == 3:
            if(not ip):
                self.state = 0
            else:
                pass

def main():
    try:
        S = list(map(int,list(input())))
    except:
        print("トレーナー!入力がちがうよ!!", file=sys.stderr)
    Teiou = AutoUmaton()
    for i in S: Teiou.transition(i)

main()

入力例

000100011

出力例

はちみー
はちみー
はちみー
はちみー
をなめるとー
あしがー
あしがー
あしがー
はやくーなる  

クラスを作るいい練習になったと思います.

おしまい

1
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
1
Help us understand the problem. What is going on with this article?