DEV Community

Saravanan Cn
Saravanan Cn

Posted on Edited on

Learning six special numbers in Python using while loops

1.Perfect Number

A perfect number is a number equal to the sum of its proper factors(excluding itself).

Example:6
Factors of 6(excluding 6)
1,2,3

Sum = 1+2+3=6

6 is a perfect number.

Another example:28
**
2.Strong Number**

It is a number which the sum of factorial its digits equal to the original number.

Example:145

1,4,5

1! = 1 x 1
4! = 4 x 3 x 2 x 1
5! = 5 x 4 x 3 x 2 x 1

120 + 24 + 1 = 145
145 is a strong number.

3.Automorphic Number:
An Automorphic Number is a number whose square ends with the same digis at the original number.

Example:
25x25=625
76x76=5776

4.Neon Number:
it is a number where the sum of the digits of its square equals the original number.
_
Example_:9
9x9=81

Sum of digits = 9
It is a Neon number.

5.Duck Number
A Duck Number is a square that contain at least one zero but zero must not be first.
Example:
102 duck number.
123 not a duck number.

6.Spy number
it is a number where the sum of its digits is equal to the product of its digits.

Example:1124

Sum of digits: 1+1+2+4=8

Product of digits: 1x1x2x4=8

Both values are equal where 1124 is a spy number.

7.Length of a string
the len() function return the total number of characters in a string.

name = 'amma'
print(len(name))

Output:
4
Enter fullscreen mode Exit fullscreen mode

**
8.Accesing the first character - positve indexing**

python index starts from 0.

python
player = 'dhoni'
print(player[0])
Output:
d
Enter fullscreen mode Exit fullscreen mode

`

9.Accesing the last character - Negative indexing.

python also supports negative indexing.

`python
python
player = 'dhoni'
pirnt([-1])

Output:
i
`

What i learnt:

  • First we have to understand the mathematical logic first makes it easier to solve problems.
  • I will continue to practise number based problems to improve my program skills.

Top comments (0)