412. Fizz Buzz
生活随笔
收集整理的这篇文章主要介绍了
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”.
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
以上
转载于:https://www.cnblogs.com/jyg694234697/p/9530243.html
总结
以上是生活随笔为你收集整理的412. Fizz Buzz的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 移动端开发框架入门
- 下一篇: 24.command-executor