228k views
2 votes
a. Write a function called fizzbuzz. This function will take 1 number as a parameter. The function will print all numbers from 0 up to the number input (non-inclusive), but, if the number is divisible by 2 you will print fizz instead, and if the number is divisible by 3 you will print buzz instead. If it is divisible by both you will print fizzbuzz

User YAHOOOOO
by
6.0k points

1 Answer

3 votes

Answer:

def fizzbuzz (num):

for item in range(num):

if item % 2 == 0 and item % 3 == 0:

print("fizzbuzz")

elif item % 3 == 0:

print("buzz")

elif item % 2 == 0:

print("fizz")

else:

print (item)

fizzbuzz(20)

Step-by-step explanation:

Using Python programming Language

Use a for loop to iterate from 0 up to the number using the range function

Within the for loop use the modulo (%) operator to determine divisibility by 2 and 3 and print the required output

see attached program output screen.

a. Write a function called fizzbuzz. This function will take 1 number as a parameter-example-1
User Natt
by
6.4k points