Skip to content

Commit

Permalink
Added Modified Kaprekar Numbers (Python) aditya109#281
Browse files Browse the repository at this point in the history
Signed-off-by: Nazish Khan <nazish1771@gmail.com>
  • Loading branch information
nazuk27 authored Oct 26, 2020
1 parent 00b8f19 commit 484df85
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/python3

# Program to find all the Kaprekar Numbers in the given range.

import math
import os
import random
import re
import sys

# Function to find the Kaprekar Numbers.
def kaprekarNumbers(p, q):
lst = []
for i in range(p, q+1):
y = len(str(i))
sq = i**2
x = len(str(sq))
r = int(sq%(10**y))
l = int(sq/(10**y))
if r+l == i:
lst.append(int(i))
if lst == []:
print("INVALID RANGE")
return
lst.sort()
for j in range(len(lst)):
print(lst[j], end=' ')


# Main funtion to take inputs
if __name__ == '__main__':
p = int(input())

q = int(input())

kaprekarNumbers(p, q)

0 comments on commit 484df85

Please sign in to comment.