412. Fizz Buzz
生活随笔
收集整理的這篇文章主要介紹了
412. Fizz Buzz
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
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”.
?
?
class Solution(object):def fizzBuzz(self, n):""":type n: int:rtype: List[str]"""output = []for i in range(n):i+=1if (i % 3 == 0 and i % 5 == 0):output.append("FizzBuzz")elif (i % 3 == 0):output.append("Fizz")elif (i % 5 == 0):output.append("Buzz")else:output.append(str(i))return output?
以上
轉(zhuǎn)載于:https://www.cnblogs.com/jyg694234697/p/9530243.html
總結(jié)
以上是生活随笔為你收集整理的412. Fizz Buzz的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 移动端开发框架入门
- 下一篇: python调用R语言,关联规则可视化