Founding Batch Offer ยท HLD ยท LLD ยท System Design at โ‚น799 until 30 Nov

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.

BeginnerPhase 1 - Level 1: Simple ConditionsExample 3 of 10
check-if-a-number-is-divisible-by-5.py
1# Take a number as input
2num = int(input("Enter a number: "))
3
4# Check if divisible by 5
5if 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. 1

    Read an integer into num.

  2. 2

    Compare num % 5 with zero.

  3. 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.