How to Examine If a Number is Strong Number in Python


In this example we will show how to figure out that if a number is a strong number or not in Python.

Source Code

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

n = int(input("Enter a number: "))
a = str(n)
sum1 = 0
for i in a:
    k = 1
    for j in range(1, int(i)+1):
        k = j * k
    sum1 += k
if sum1 == n:
    print("The number is a strong number.")
else:
    print("The number is not a strong number.")

Output:

Enter a number: 145
The number is a strong number.

Enter a number: 256
The number is not a strong number.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments