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