LoginSignup
1
2

More than 5 years have passed since last update.

世界のナベアツをPythonの関数にしてみた

Posted at

世界のナベアツ=「3の倍数と3が付く数字の時だけアホになります」という芸を持つ芸人。
ということで、世界のナベアツをPythonの関数にしましたw

…以下のnabeatsu.pyの中で定義してるnabeatsu()がそれ。
1から引数に与えた数字まで評価し、数字が3の倍数と3が付く数字の時には"Aho"という文字列とその時の数字を、それ以外の時は数字を出力する。
残骸がいろいろ残ってるけどご愛敬w

nabeatsu.py

import os
import sys

def nabeatsu(numb):
    keta = 1
    cnt = 1
    while True:
        if(10 ** (keta - 1)) == numb:
            break
        else:
            if(10 ** (keta - 1)) > numb:
                keta = keta - 1
                break
            else:
                keta = keta + 1

    print("%d" % keta)


    while True:
        if(cnt % 3) == 0:
            print("Aho %d" % cnt)
        else:
            if("3" in str(cnt)):
                print("Aho %d" % cnt)
            else:
                print("%d" % cnt)
        if cnt == numb:
            break
        else:
            cnt = cnt + 1

def main():
    nabeatsu(100)

if __name__ == '__main__':
    main()

1
2
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2