In this Python if else program we will check if a number is divisible by 3 or not. Print the number divisible by 3.
Divisibility test: The divisibility rule for 3 states that a number is completely divisible by 3 if the sum of its digits is divisible by 3.
Steps to solve the program
- Take a number as input through the user.
- Check whether that given number is divisible by 3, using an if else statement.
- Print the respective output.
# Take input through the user
num = int(input("Please enter number :"))
# Check whether the number is divisible by 3
if num%3 == 0:
# Print output
print("Number is divisible by 3")
else:
# Print output
print("Number is not divisible by 3")
Output :
Please enter number : 14
Number is not divisible by 3
Please enter number : 21
Number is divisible by 3
Related Articles
- If else program to get all the numbers divided by 3 from 1 to 30.
- If else program to assign grades as per total marks.
- Python program to check the given number divided by 3 and 5.
- Python program to print the square of the number if it is divided by 11.
- Python program to check given number is a prime number or not.
- Python program to check given number is odd or even.
get all the numbers divided by 3 from 1 to 30.