欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

412. Fizz Buzz

发布时间:2024/4/17 编程问答 47 豆豆
生活随笔 收集整理的这篇文章主要介绍了 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的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。