In this python if else program, we will check whether the number id divided by the numbers are given in the question and print FIzz-Buzz according to it.
Steps to solve the program
- Take a number as input through the user.
- If a multiple of two print “Fizz” instead of the number and for the multiples of three print “Buzz”.
- For numbers that are multiples of both two and three print “FizzBuzz”.
- Use if-else statements for this purpose.
num = int(input("Enter a number: "))
if num%2 == 0 and num%3 == 0:
print("FizzBuzz")
elif num%2 == 0:
print("Fizz")
elif num%3 == 0:
print("Buzz")
Output :
Enter a number: 6
FizzBuzz
Related Articles
Python program to check whether an alphabet is a vowel.
Python program to check whether an alphabet is a consonant.
Python program to convert the month name to the number of days.
Python program to check whether a triangle is equilateral or not.
Python program to check whether a triangle is scalene or not.
Python program to check whether a triangle is isosceles or not.