Fizzbuzz Program in Python using Functions.
Write a function with the name fizz_buzz that takes a number as an argument.
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.
Input
The first line of input will contain an integer.
Output
The output should be a single line containing the word according to the above conditions.
Explanation
For example, if the given number is 20, the output should be “Buzz” as 20 is divisible by 5 and not divisible by 3.
Whereas the given number is 7, the output should be 7, as 7 is not divisible by neither 3 nor 5.
Sample Input 1
20
Sample Output 1
BUZZ
Sample Input 2
7
Sample Output 2
7
Code:
def fizz_buzz(number):
if number%3==0 and number%5==0:
result="FizzBuzz"
elif number%3==0:
result="Fizz"
elif number%5==0:
result="Buzz"
else:
result=number
return result
number = int(input())
output=fizz_buzz(number)
print(output)
Input
15
Output
FizzBuzz