Answers for "fizz buzz py"

2

fizz buzz python

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"
    else:
        return input


print(fizz_buzz(3))
Posted by: Guest on June-22-2020
0

python fizzbuzz solution

# check prime number
def prime(n):
    if n > 1:
        for i in range(2, n):
            if (n % i) == 0:
                break
        else:
            print(n, "prime number")


for num in range(1, 100):
    result = ""
    if prime(num):
        result += "Prime"
    else:
        if num % 3 == 0 and num % 5 == 0:
            result += "FizzBuzz"
            print(num, result)
        elif num % 3 == 0:
            result += "Fizz"
            print(num, result)
        elif num % 5 == 0:
            result += "Buzz"
            print(num, result)
        else:
            print(num)


if __name__ == '__main__':

    print('All done')
Posted by: Guest on August-22-2020

Python Answers by Framework

Browse Popular Code Answers by Language