Remember the game of FizzBuzz from the last time? Well, I thought of some changes in the game, and also with the help of loops as well. Firstly, you'll be asking for a random integer and then loop from 1 until that integer. Then, implement these conditions in the game:
Input
A line containing an integer.
15
Output
Multiple lines containing a string or an integer.
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
def is_div_by_3(x):
return x % 3 == 0
def is_div_by_5(x):
return x % 5 == 0
n = int(input())
for i in range(1, n + 1):
if is_div_by_3(i) and is_div_by_5(i):
print('FizzBuzz')
elif is_div_by_3(i):
print('Fizz')
elif is_div_by_5(i):
print('Buzz')
else:
print(i)
Comments
Leave a comment