Created
November 15, 2019 01:17
-
-
Save cacapon/58b9aa194c7d5ff78878fe48b3666dc8 to your computer and use it in GitHub Desktop.
修正4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# TODOを対応してみる | |
START_NUM = 1 # fizzbuzz開始位置 | |
END_NUM = 30 # fizzbuzz終了位置 | |
# fizzbuzzに使う単語とどこで呼ばれるかを設定します。 | |
word_list = ['fizz', 'buzz', 'fizzbuzz'] # 3つまで # TODO:単語数を増やしたりできないかな? | |
number_associated_with_word = {word_list[0]: 3, word_list[1]: 5, word_list[2]: 15} # HACK:翻訳で付けた。wordに関連する数…的な名前にしたい。 | |
def play_fizzbuzz(): | |
# START_NUMからEND_NUMまで指定の数まで繰り返し、 | |
# fizzbuzzを出力します。 | |
for count in range(START_NUM, END_NUM + 1): # ENDに+1しているのはrangeが終了の数-1で止まってしまうため。 | |
if count % number_associated_with_word[word_list[2]] == 0: | |
print("{}:{}".format(count, word_list[2])) | |
elif count % number_associated_with_word[word_list[0]] == 0: | |
print("{}:{}".format(count, word_list[0])) | |
elif count % number_associated_with_word[word_list[1]] == 0: | |
print("{}:{}".format(count, word_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