题目要求:
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( )
时间: 2024-10-13 17:47:39