- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to find keith numbers using Python?
You can use the following code to find if a number is a keith number in python −
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 < n: a = a[1:] + [b] b = sum(a) return (b == n) & (len(c) > 1) print(is_keith_number(14))
This will give the output −
- Keith Number in C++
- How to Find the Largest Among Three Numbers using Python?
- How to Find the Sum of Natural Numbers using Python?
- How to find Kaprekar numbers within a given range using Python?
- How to Find Sum of Natural Numbers Using Recursion in Python?
- How to add binary numbers using Python?
- How to multiply large numbers using Python?
- How to divide large numbers using Python?
- How to generate prime numbers using Python?
- How to convert numbers to words using Python?
- How to find minimum between 2 numbers using C#?
- How to find maximum between 2 numbers using C#?
- Python Program to Find the Product of two Numbers Using Recursion
- Python program to find product of rational numbers using reduce function
- How to generate pyramid of numbers using Python?