412. Fizz Buzz

Write a program that outputs the string representation of numbers from 1 to n.

But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For numbers which are multiples of both three and five output “FizzBuzz”.

    def fizzBuzz(self, n):
        """
        :type n: int
        :rtype: List[str]
        """
        nums = []
        for i in range(1,n+1):
            if (i%3 != 0 and i%5 !=0):
                nums.append(str(i))
            elif i%15 == 0:
                nums.append('FizzBuzz')
            elif i%3 == 0:
                nums.append('Fizz')
            else:
                nums.append('Buzz')
        return nums

沒啥說的,注意i不能打出來就好,str(就可以了)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • 你過的不好 我會等 你過的好 我不打擾
    0826_初閱讀 204評論 0 0
  • 阿里想做社交,一直是大家眾所周知的事兒,從幾乎銷聲匿跡的“來往”到支付寶 9.0 版強行加入的社交屬性。但直到最近...
    浪里個男閱讀 939評論 0 5
  • 斜陽無意向晚,誰堪想,日影斷。墨染經(jīng)年夢未全,書攜流景心欲遠。題詩賦萬卷。 四分之一春秋,只換來日安候。爍星春夜倦...
    四月未及閱讀 366評論 0 0
  • 5年前的辭職報告,緬懷一下過去的日子 尊敬的郎組織: 我志愿離開今麥郎,不再接受郎的領(lǐng)導(dǎo),不再聽從郎的指揮…… 悄...
    大唐逸民閱讀 150評論 0 2