You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: easyPythonpi/easyPythonpi.py
+38-36Lines changed: 38 additions & 36 deletions
Original file line number
Diff line number
Diff line change
@@ -5,42 +5,42 @@
5
5
'from module import *' and u r good to go...
6
6
~Happy programming"""
7
7
8
-
defadd(x, y): # For addition of 2 numbers
8
+
defadd(x:'float', y:'float')->'float': # For addition of 2 numbers
9
9
returnx+y
10
10
11
-
defsub(x, y): # For substraction of 2 numbers
11
+
defsub(x:'float', y:'float')->'float': # For substraction of 2 numbers
12
12
returnx-y
13
13
14
-
defmulti(x, y): # For multiplication of 2 numbers
14
+
defmulti(x:'float', y:'float')->'float': # For multiplication of 2 numbers
15
15
returnx*y
16
16
17
-
defdiv(x, y): # For division of 2 numbers
17
+
defdiv(x:'float', y:'float')->'float': # For division of 2 numbers
18
18
returnx/y
19
19
20
-
defmod(x, y): # For finding the modulus of 2 numbers
20
+
defmod(x:'float', y:'float')->'float': # For finding the modulus of 2 numbers
21
21
returnx%y
22
22
23
-
deffactorial(n): # To find the factorial of 2 numbers
23
+
deffactorial(n:'int')->'int': # To find the factorial of 2 numbers
24
24
# single line to find factorial
25
25
return1if (n==1orn==0) elsen*factorial(n-1)
26
26
27
27
# To compute the factord of the argument passed
28
-
deffactors(n):
28
+
deffactors(n:'int')->'int':
29
29
factors= []
30
30
foriinrange(1, n+1):
31
31
ifn%i==0:
32
32
factors.append(i)
33
33
returnfactors
34
34
35
-
defArea_circle(r): # To find the area of a circle using the radius r
35
+
defArea_circle(r:'double')->'double': # To find the area of a circle using the radius r
36
36
PI=3.142
37
37
returnPI* (r*r)
38
38
39
-
defPerimeter_circle(r): # To find the perimeter of a circle using the radius r
39
+
defPerimeter_circle(r:'float')->'float': # To find the perimeter of a circle using the radius r
40
40
PI=3.142
41
41
return2*PI*r
42
42
43
-
deffibonacci(n): #To find the nth fibonacci series
43
+
deffibonacci(n:'int')->'int': #To find the nth fibonacci series
44
44
ifn<0:
45
45
print("Incorrect input")
46
46
# First Fibonacci number is 0
@@ -52,7 +52,7 @@ def fibonacci(n): #To find the nth fibonacci series
52
52
else:
53
53
returnfibonacci(n-1)+fibonacci(n-2)
54
54
55
-
defsort(list): # To bubble sort and array or list
55
+
defsort(list:'list'): # To bubble sort and array or list
56
56
foriinrange(len(list) -1, 0, -1):
57
57
forjinrange(i):
58
58
iflist[j] >list[j+1]:
@@ -61,19 +61,22 @@ def sort(list): # To bubble sort and array or list
61
61
list[j+1] =temp
62
62
63
63
#method to print the 1st prime number between the range
64
-
defprintprime(start,end):
64
+
defprintprime(start:'int',end:'int')->'list':
65
65
ifstart<=0:
66
-
start=1
66
+
start=2
67
+
p=[]
67
68
foriinrange(start,end+1):
68
69
j=0
69
70
forkinrange(2,i):
70
71
ifi%k==0:
71
72
j=1
73
+
break
72
74
ifj==0:
73
-
returni
74
-
75
+
p.append(i)
76
+
77
+
returnp
75
78
#A method to convert Hexadecimal input to binary numbers
76
-
defhex2bin(x):
79
+
defhex2bin(x:'hex')->'bin':
77
80
x=str(x)
78
81
r=''
79
82
foriinx:
@@ -93,15 +96,15 @@ def hex2bin(x):
93
96
h=bin(int(i))
94
97
n=h[2:]
95
98
forjinrange(4):
96
-
iflen(n)<4:
99
+
iflen(n)<4:
97
100
n='0'+n
98
101
99
102
r=r+n
100
103
returnr
101
104
102
105
103
106
#A method to convert Octal input to binary numbers
104
-
defoct2bin(x):
107
+
defoct2bin(x:'oct')->'bin':
105
108
r=''
106
109
x=str(x)
107
110
foriinx:
@@ -114,7 +117,7 @@ def oct2bin(x):
114
117
returnr
115
118
116
119
#A method to convert binary input to decimal numbers
117
-
defbin2dec(x):
120
+
defbin2dec(x:'bin')->'dec':
118
121
x=list(str(x))
119
122
l=len(x)
120
123
a=0
@@ -127,7 +130,7 @@ def bin2dec(x):
127
130
returnr
128
131
129
132
130
-
defcreatearray(length,dtype='int'): # To create an array of entered length and entered data type(interger data type is a default data type)
133
+
defcreatearray(length:'int',dtype='int')->'array': # To create an array of entered length and entered data type(interger data type is a default data type)
131
134
importnumpyasnp
132
135
a=[] #empty list
133
136
foriinrange(length):
@@ -148,15 +151,15 @@ def createarray(length,dtype='int'): # To create an array of entered length an
148
151
b=np.array(a)
149
152
returnb
150
153
151
-
defarrayrev(array): # To reverese the array elements
154
+
defarrayrev(array:'array')->'array': # To reverese the array elements
152
155
importnumpyasnp
153
156
r=[]
154
157
foriinrange(len(array)-1,-1,-1):
155
158
r.append(array[i])
156
159
a=np.array(r)
157
160
returna
158
161
159
-
defispalindrome(x): # To check if the given parameter is palindrome or not
162
+
defispalindrome(x:'str')->'str': # To check if the given parameter is palindrome or not
160
163
x=str(x) #explicitly convert into string data type so as to iterate through each character
161
164
r=''
162
165
foriinrange(len(x)-1,-1,-1):
@@ -168,7 +171,7 @@ def ispalindrome(x): # To check if the given parameter is palindrome or n
168
171
169
172
170
173
171
-
defeven_or_odd(data):
174
+
defeven_or_odd(data:'int'):
172
175
try :
173
176
ifdata%2==0:
174
177
return'even'
@@ -181,7 +184,7 @@ def even_or_odd(data):
181
184
182
185
#Linked list
183
186
184
-
defcreate_node(data):
187
+
defcreate_node(data:'int')->'Linked list':
185
188
classnode:
186
189
def__init__(self,data):
187
190
self.data=data
@@ -191,15 +194,15 @@ def __init__(self,data):
191
194
returna
192
195
# to link a node with another node
193
196
194
-
defnode_link(a,b):
197
+
defnode_link(a:'int',b:'int'):
195
198
a.next=b
196
199
b.next=None
197
200
#a=node(data1)
198
201
199
202
200
203
# to count number of nodes
201
204
202
-
defcount_node(head):
205
+
defcount_node(head:'node')->'int':
203
206
ifheadisNone:
204
207
return0
205
208
else:
@@ -212,7 +215,7 @@ def count_node(head):
212
215
213
216
# to diplay a linked list whose header node is passed as an argument
0 commit comments