1. FizzBuzz 2.0
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:
• print "Fizz" if the number is divisible by 3.
• print "Buzz" if the number is divisible by 5.
• print "FizzBuzz" if the number is divisible by both 3 and 5.
• print the number itself if none of the above conditions are met.
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
N=int(input("Enter the value of N: "))
for N in range(1,16):
if N % 3 == 0 and N % 5 == 0:
print("fizzbuzz")
continue
elif N % 3 == 0:
print("fizz")
continue
elif N % 5 == 0:
print("buzz")
continue
print(N)
output sample:
Enter the value of N: 15
1
2
fizz
4
buzz
fizz
7
8
fizz
buzz
11
fizz
13
14
fizzbuzz
Comments
Leave a comment