2 views
in Python

I am composing a function fizzbuzz and what I need to do is input value and return it as fizz, buzz, or fizzbuzz. Be that as it may, there is an issue with my code. At whatever point I run this, I simply just get the primary condition and it doesn't proceed. Here is the code underneath for you:

a=int(input('Enter a number: '))

def fizzbuzz(a):

if a % 3 == 0:

return ('Fizz')

elif a % 5 == 0:

return ( 'Buzz' )

elif a % 15 == 0:

return ('Fizzbuzz')

else:

return a

print(fizzbuzz(a))

by (26.4k points)
edited by

Be certain that your conditions are checked organized appropriately.

A Fizzbuzz number is likewise a Fizz (divisible by 3) and a Buzz (divisible by 5), just all things considered. In the code, you composed on the off chance that you inquire as to whether 15 is a Buzz since it is the first check, you will get a positive outcome.

The condition you need to test here isn't if a number is divisible by 15 yet in the event that a number is divisible by 3 and 5 simultaneously.

Given this clarification you need to compose conditions a piece in an unexpected way:

a=int(input('Enter a number: '))

def fizzbuzz(a):

if a % 3 == 0 and a % 5 == 0:

return('Fizzbuzz')

elif a % 3 == 0:

return('Fizz')

elif a % 5 == 0:

return('Buzz')

else:

return a

print(fizzbuzz(a))

Interested to learn python in detail? Come and Join the python course.

Watch this video tutorial on how to become a professional in python