Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Find Keith Numbers Using Python



You can use the following code to find if a number is a keith number in python −

Example

def is_keith_number(n):
   # Find sum of digits by first getting an array of all digits then adding them
   c = str(n)
   a = list(map(int, c))
   b = sum(a)

   # Now check if the number is a keith number
   # For example, 14 is a keith number because:
   # 1+4 = 5
   # 4+5 = 9
   # 5+9 = 14

   while b  1)
print(is_keith_number(14))

Output

This will give the output −

True
Updated on: 2020-03-05T11:23:28+05:30

729 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements