-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathModifiedKaprekarsNumber.py
53 lines (50 loc) · 1.05 KB
/
ModifiedKaprekarsNumber.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 11 21:18:26 2020
@author: ravi
"""
li = []
def kaprekar(n):
if n == 1:
li.append(n)
if n>=2 and n < 10:
q = n**2
q = str(q)
l = len(q)
if l>=2:
q = n**2
q = str(q)
l = len(q)
x = l//2
temp1 = ""
temp2 = ""
temp1 = temp1 + q[:x]
temp2 = temp2 + q[x:l]
temp1 = int(temp1)
temp2 = int(temp2)
add = temp1+temp2
if add == n:
li.append(n)
if n>=10:
q = n**2
q = str(q)
l = len(q)
x = l//2
temp1 = ""
temp2 = ""
temp1 = temp1 + q[:x]
temp2 = temp2 + q[x:l]
temp1 = int(temp1)
temp2 = int(temp2)
add = temp1+temp2
if add == n:
li.append(n)
p = int(input())
q = int(input())
for i in range(p,q+1):
kaprekar(i)
if len(li)!=0:
print(*li,sep = " ")
else:
print("INVALID RANGE")