Junior — Senior
Output of numbers from 1 to 100 with FizzBuzz rules replacement
livecode
Task condition
It is required to implement a function that prints a sequence of numbers from 1 to 100. In this sequence:
- if a number is divisible by 3 without a remainder, the string "Fizz" is printed instead;
- if a number is divisible by 5 without a remainder, the string "Buzz" is printed;
- if a number is divisible by both 3 and 5, the string "FizzBuzz" is printed;
- in all other cases, the number itself is printed.
def main():
for i in range(1, 101):
if i%15 == 0:
print("FizzBuzz")
elif i%3 == 0:
print("Fizz")
elif i%5 == 0:
print("Buzz")
else:
print(i)
main()