'''
输入一个正整数n,返回一个list,list中的内容为1到n,但是将其中3的倍数替换为'Fizz',5的倍数替换为'Buzz',同时为3和5的倍数的替换为'FizzBuzz'
例子
15 ->
[ '1', '2', 'Fizz', '4', 'Buzz', 'Fizz', '7', '8', 'Fizz', 'Buzz', '11', 'Fizz', '13', '14', 'FizzBuzz' ]
tips
1.利用取模运算
'''
def fizz_buzz(n):
alist = []
for i in range(1, n+1):
if i % 3 == 0 and i % 5 == 0:
alist.append('FizzBuzz')
elif i % 3 == 0:
alist.append('Fizz')
elif i % 5 == 0:
alist.append('Buzz')
else:
alist.append(str(i))
return alist
n = 30
print(fizz_buzz(n))