Check if a Number is Divisible by 5
Test divisibility by five with a short Python program. Beginners can trace int input, a modulo comparison, and the two possible printed results step by step.
1# Take a number as input2num = int(input("Enter a number: "))34# Check if divisible by 55if num % 5 == 0:6 print("Divisible by 5")7else:8 print("Not divisible by 5")
Output
Enter a number: 25 Divisible by 5 Enter a number: 13 Not divisible by 5
In this one
- Define exact divisibility
- Use modulo five
- Choose an else result
How it works
- 1
Read an integer into num.
- 2
Compare num % 5 with zero.
- 3
Print the corresponding divisibility message.
Edge cases
What about zero?
What about zero?
Zero passes because 0 % 5 is 0.
What about -15?
What about -15?
It also passes; the sign does not prevent exact divisibility.
What's going on
Divisible by five means there is no remainder after division by five. The program reads a whole number, then compares num % 5 with zero.
For 25, the remainder is zero and the first print runs. For 13, the remainder is three and else runs. This is an arithmetic test; it does not inspect the last character of the typed response.
What about zero? Zero passes because 0 % 5 is 0.
What about -15? It also passes; the sign does not prevent exact divisibility.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
What does 13 % 5 return?
Pick an answer to check it.
Question 2
What about zero?
Pick an answer to check it.
Questions people ask
What about zero?
Zero passes because 0 % 5 is 0.
What about -15?
It also passes; the sign does not prevent exact divisibility.
What does 13 % 5 return?
3.
๐Related Content
- ๐
Phase 1 - Learn Concepts
Review Phase 1 concepts and explanations
- ๐
Phase 1 - Quiz
Test your Phase 1 understanding with quiz questions
- ๐ป
Phase 1 - All Practice Problems
Explore all practice problems for Phase 1
- ๐
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- ๐ง
Logic Building Overview
Learn about the complete logic building curriculum