mardi 25 février 2020

How do I write the fizzbuzz function in Python 3 with an input value?

I am writing a function fizzbuzz and what I want to do is input value and return it as fizz, buzz or fizzbuzz. However, there is a problem with my code. Whenever I run this, I just only get the first condition and it does not continue. Here is the code below 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))

Aucun commentaire:

Enregistrer un commentaire