Answer to Question #329509 in Python for Shubham Tiwari

Question #329509

Write a function called fizz_buzz that takes a number.

If the number is divisible by 3, it should return “Fizz”.

If it is divisible by 5, it should return “Buzz”.

If it is divisible by both 3 and 5, it should return “FizzBuzz”.

Otherwise, it should return the same number.


1
Expert's answer
2022-04-16T11:42:00-0400
def fizzbuzz(num):
	if num%3 == 0 or num%5 == 0:
		s = ''
		if num%3 == 0:
			s += 'Fizz'
		if num%5 == 0:
			s += 'Buzz'
		return s
	else:
		return num


print(fizzbuzz(3))
print(fizzbuzz(5))
print(fizzbuzz(15))
print(fizzbuzz(4))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS