Statement:
Write the code needed to print to the console all the numbers from 1 to 100.
- For multiples of 3, instead of the number, print Fizz.
- For multiples of 5, print Buzz.
- For numbers which are multiples of both 3 and 5, print FizzBuzz.
Solution:
for i in range(1, 101):
if i % 3 == 0:
print("Fizz")
elif i % 5 == 0:
print("Buzz")
else:
print(i)
if i % 3 == 0 and i % 5 == 0:
print("FizzBuzz")
Top comments (0)