Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

FIZZBUZZ ALGORITHM

def fizz_buzz(input):
    if input % 3 == 0 and not input % 5 == 0:
        return "Fizz"
    if input % 5 == 0 and not input % 3 == 0:
        return "Buzz"
    if (input % 3 == 0) and (input % 5 == 0):
        return "FizzBuzz"

    return input

print(fizz_buzz(15))



# OR MORE SIMPLIFIED



def fizz_buzz(input):
    if (input % 3 == 0) and (input % 5 == 0):
        return "FizzBuzz"
    if input % 3 == 0:
        return "Fizz"
    if input % 5 == 0:
        return "Buzz"

    return input


print(fizz_buzz(15))
 
PREVIOUS NEXT
Tagged: #FIZZBUZZ #ALGORITHM
ADD COMMENT
Topic
Name
3+7 =