- 4th Apr 2023
- 08:08 am
- Admin
Python Homework Help
Python Homework Question
Python Logical Puzzles, Games, and Algorithms: FizzBuzz
Python Homework Solution
Here's an implementation of FizzBuzz in Python
Python:
for i in range(1, 101):
if i % 3 == 0 and i % 5 == 0:
print("FizzBuzz")
elif i % 3 == 0:
print("Fizz")
elif i % 5 == 0:
print("Buzz")
else:
print(i)
Both of these implementations work in the same way. We use a loop to iterate over the numbers from 1 to 100, and for each number, we use a series of conditional statements to determine what to print. If the number is divisible by both 3 and 5, we print "FizzBuzz". If it's only divisible by 3, we print "Fizz". If it's only divisible by 5, we print "Buzz". Otherwise, we just print the number itself.