Check if a Number is Divisible by 5

Check if a number is divisible by 5.

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

What's going on

A number is divisible by 5 if the remainder when divided by 5 is 0.

Key Concepts:

Use modulo operator to check divisibility
num % 5 == 0 means num is divisible by 5
Otherwise, num is not divisible by 5