首页 > 其他 > 详细

leetcode--笔记8 Fizz Buzz

时间:2016-11-01 18:35:25      阅读:181      评论:0      收藏:0      [点我收藏+]

题目要求:

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”.

 

my answer:

技术分享

测试错误分析

1 range(n)的使用,记住range(2)代表0,1 是从0开始的,所以上述遍历之后的 i 要变为 i+1

2 s%3==0 , 对于小于3的数也是成立的,所以这里分开讨论了

3 首先if 同时整除3和5的数,否则会出错

4 如果 output.append(“u”),直接加双引号会出错,输出"u" ,而不输出遍历的数字,所以需要用函数 str( )

 

leetcode--笔记8 Fizz Buzz

原文:http://www.cnblogs.com/qicaide/p/6020296.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!