Skip to content

Instantly share code, notes, and snippets.

@cacapon
Created November 15, 2019 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cacapon/6a588a1209d8f791b3d49fcde5680d28 to your computer and use it in GitHub Desktop.
Save cacapon/6a588a1209d8f791b3d49fcde5680d28 to your computer and use it in GitHub Desktop.
修正3
# 行間,コメント間隔を揃える
START_NUM = 1 # fizzbuzz開始位置
END_NUM = 30 # fizzbuzz終了位置
def play_fizzbuzz():
# START_NUMからEND_NUMまでのfizzbuzzを出力します。
str_list = ['fizz', 'buzz', 'fizzbuzz'] # 3単語までしか対応していません。
for count in range(START_NUM, END_NUM + 1): # ENDに+1しているのはrangeが終了の数-1で止まってしまうため。
# TODO:15とか3とか5を変数で管理したい
if count % 15 == 0:
print("{}:{}".format(count, str_list[2]))
elif count % 3 == 0:
print("{}:{}".format(count, str_list[0]))
elif count % 5 == 0:
print("{}:{}".format(count, str_list[1]))
else:
print("{}:".format(count))
play_fizzbuzz()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment