forked from aditya109/git-osp-for-beginners
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Modified Kaprekar Numbers (Python) aditya109#281
Signed-off-by: Nazish Khan <nazish1771@gmail.com>
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
Programming/Python/ModifiedKaprekarNumber/ModifiedKaprekarNumber.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |