Python Practice › If-Else Programs › Program 5
Square a number divisible by 11
Write a Python program to print the square of a number if it is divisible by 11.
Input
121, 50
Output
121 is divisible by 11, square = 14641 50 is not divisible by 11
Approach
- Check
n % 11 == 0; if true printn ** 2.
Solution
for n in [121, 50]: if n % 11 == 0: print(f"{n} is divisible by 11, square = {n ** 2}") else: print(f"{n} is not divisible by 11")Output
121 is divisible by 11, square = 14641 50 is not divisible by 11
Line by line
Line 3
The square is calculated inside the f-string.
Learn the concept
New to this topic? Read the lesson, then come back.