Square a number divisible by 11

EasyIf-Else Programs · 5 of 64

Write a Python program to print the square of a number if it is divisible by 11.

Advertisement
Input
121, 50
Output
121 is divisible by 11, square = 14641
50 is not divisible by 11

Approach

  1. Check n % 11 == 0; if true print n ** 2.

Solution

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

Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More if-else programs

← All 64 If-Else Programs