20 lines
556 B
Python
20 lines
556 B
Python
|
G
|
def fb(n):
|
||
|
|
"""Return a list of strings for numbers 1..n with FizzBuzz rules.
|
||
|
|
Multiples of 3 -> 'Fizz', multiples of 5 -> 'Buzz', both -> 'FizzBuzz', else the number as a string.
|
||
|
|
"""
|
||
|
|
result = []
|
||
|
|
for i in range(1, n+1):
|
||
|
|
if i % 15 == 0:
|
||
|
|
result.append('FizzBuzz')
|
||
|
|
elif i % 3 == 0:
|
||
|
|
result.append('Fizz')
|
||
|
|
elif i % 5 == 0:
|
||
|
|
result.append('Buzz')
|
||
|
|
else:
|
||
|
|
result.append(str(i))
|
||
|
|
return result
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
# Simple verification
|
||
|
|
print(fb(15))
|