-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAssign 9 python.txt
99 lines (82 loc) · 2.53 KB
/
Assign 9 python.txt
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
def Disarium(num):
sum = 0
while(num>0):
l= len(str(num))
no = num%10
sum= sum + no**l
l-=1
num = num//10
return sum
num = int(input("Enter the number :"))
sum = Disarium(num)
if sum == num:
print(num,"Number is Disarium")
else:
print(num,"Number is not Disarium")
#A number is said to be the Disarium number when the sum of its digit
# raised to the power of their respective positions becomes equal to the number itself.
**************************************************************************************************
def Disarium(num):
sum = 0
while(num>0):
l= len(str(num))
no = num%10
sum= sum + no**l
l-=1
num = num//10
return sum
print("Disarium no in range 1 to 100")
disno = []
for i in range(1,101):
sum = 0
sum = Disarium(i)
if sum == i:
disno.append(i)
print(disno)
************************************************************************
def Happy(num):
sum = 0
while(num>0):
dig = num%10
sum= sum + dig**2
num = num//10
return sum
num = int(input("Enter the number :"))
result = num
while (result != 1 and result != 4):
result = Happy(result)
if result == 1:
print(num,"Is a Happy Number")
else:
print(num," Is a Unhappy Number")
#A number is said to be happy if it yields 1 when replaced by the sum of squares of its digits repeatedly.
# If this process results in an endless cycle of numbers containing 4, then the number will be an unhappy number.
***************************************************************************************************************************
def digsum(num):
sum = 0
while(num>0):
dig = num%10
sum= sum + dig
num = num//10
return sum
num = int(input("Enter no. :"))
sum = digsum(num)
if num % sum == 0:
print(num,"Is a Harshad number")
else:
print(num,"Is not a Harshad number")
#if a number is divisible by the sum of its digits, then it will be known as a Harshad Number
****************************************************************************************************
def PronicNo(num):
Pronic = False
for i in range(1,num+1):
if i*(i+1) == num:
Pronic = True
break
return Pronic
print("Pronic numbers in range 1 to 100")
pronicno = []
for i in range(1,101):
if PronicNo(i):
pronicno.append(i)
print(pronicno)