Skip to content

Commit 6d9c546

Browse files
authored
updated with annotations (#25)
Well done!
1 parent 0576a5d commit 6d9c546

File tree

1 file changed

+38
-36
lines changed

1 file changed

+38
-36
lines changed

easyPythonpi/easyPythonpi.py

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,42 @@
55
'from module import *' and u r good to go...
66
~Happy programming"""
77

8-
def add(x, y): # For addition of 2 numbers
8+
def add(x:'float', y:'float')->'float': # For addition of 2 numbers
99
return x+y
1010

11-
def sub(x, y): # For substraction of 2 numbers
11+
def sub(x:'float', y:'float')->'float': # For substraction of 2 numbers
1212
return x-y
1313

14-
def multi(x, y): # For multiplication of 2 numbers
14+
def multi(x:'float', y:'float')->'float': # For multiplication of 2 numbers
1515
return x*y
1616

17-
def div(x, y): # For division of 2 numbers
17+
def div(x:'float', y:'float')->'float': # For division of 2 numbers
1818
return x/y
1919

20-
def mod(x, y): # For finding the modulus of 2 numbers
20+
def mod(x:'float', y:'float')->'float': # For finding the modulus of 2 numbers
2121
return x%y
2222

23-
def factorial(n): # To find the factorial of 2 numbers
23+
def factorial(n:'int')->'int': # To find the factorial of 2 numbers
2424
# single line to find factorial
2525
return 1 if (n == 1 or n == 0) else n * factorial(n - 1)
2626

2727
# To compute the factord of the argument passed
28-
def factors(n):
28+
def factors(n:'int')->'int':
2929
factors = []
3030
for i in range(1, n+1):
3131
if n % i == 0:
3232
factors.append(i)
3333
return factors
3434

35-
def Area_circle(r): # To find the area of a circle using the radius r
35+
def Area_circle(r:'double')->'double': # To find the area of a circle using the radius r
3636
PI = 3.142
3737
return PI * (r * r)
3838

39-
def Perimeter_circle(r): # To find the perimeter of a circle using the radius r
39+
def Perimeter_circle(r:'float')->'float': # To find the perimeter of a circle using the radius r
4040
PI = 3.142
4141
return 2 * PI * r
4242

43-
def fibonacci(n): #To find the nth fibonacci series
43+
def fibonacci(n:'int')->'int': #To find the nth fibonacci series
4444
if n<0:
4545
print("Incorrect input")
4646
# First Fibonacci number is 0
@@ -52,7 +52,7 @@ def fibonacci(n): #To find the nth fibonacci series
5252
else:
5353
return fibonacci(n-1)+fibonacci(n-2)
5454

55-
def sort(list): # To bubble sort and array or list
55+
def sort(list:'list'): # To bubble sort and array or list
5656
for i in range(len(list) - 1, 0, -1):
5757
for j in range(i):
5858
if list[j] > list[j + 1]:
@@ -61,19 +61,22 @@ def sort(list): # To bubble sort and array or list
6161
list[j + 1] = temp
6262

6363
#method to print the 1st prime number between the range
64-
def printprime(start,end):
64+
def printprime(start:'int',end:'int')->'list':
6565
if start<=0:
66-
start=1
66+
start=2
67+
p=[]
6768
for i in range(start,end+1):
6869
j=0
6970
for k in range(2,i):
7071
if i%k==0:
7172
j=1
73+
break
7274
if j==0:
73-
return i
74-
75+
p.append(i)
76+
77+
return p
7578
#A method to convert Hexadecimal input to binary numbers
76-
def hex2bin(x):
79+
def hex2bin(x:'hex')->'bin':
7780
x=str(x)
7881
r=''
7982
for i in x:
@@ -93,15 +96,15 @@ def hex2bin(x):
9396
h=bin(int(i))
9497
n=h[2:]
9598
for j in range(4):
96-
if len(n)<4:
99+
if len(n)<4:
97100
n='0'+n
98101

99102
r=r+n
100103
return r
101104

102105

103106
#A method to convert Octal input to binary numbers
104-
def oct2bin(x):
107+
def oct2bin(x:'oct')->'bin':
105108
r=''
106109
x=str(x)
107110
for i in x:
@@ -114,7 +117,7 @@ def oct2bin(x):
114117
return r
115118

116119
#A method to convert binary input to decimal numbers
117-
def bin2dec(x):
120+
def bin2dec(x:'bin')->'dec':
118121
x=list(str(x))
119122
l=len(x)
120123
a=0
@@ -127,7 +130,7 @@ def bin2dec(x):
127130
return r
128131

129132

130-
def createarray(length,dtype='int'): # To create an array of entered length and entered data type(interger data type is a default data type)
133+
def createarray(length:'int',dtype='int')->'array': # To create an array of entered length and entered data type(interger data type is a default data type)
131134
import numpy as np
132135
a=[] #empty list
133136
for i in range(length):
@@ -148,15 +151,15 @@ def createarray(length,dtype='int'): # To create an array of entered length an
148151
b=np.array(a)
149152
return b
150153

151-
def arrayrev(array): # To reverese the array elements
154+
def arrayrev(array:'array')->'array': # To reverese the array elements
152155
import numpy as np
153156
r=[]
154157
for i in range(len(array)-1,-1,-1):
155158
r.append(array[i])
156159
a=np.array(r)
157160
return a
158161

159-
def ispalindrome(x): # To check if the given parameter is palindrome or not
162+
def ispalindrome(x:'str')->'str': # To check if the given parameter is palindrome or not
160163
x=str(x) #explicitly convert into string data type so as to iterate through each character
161164
r=''
162165
for i in range(len(x)-1,-1,-1):
@@ -168,7 +171,7 @@ def ispalindrome(x): # To check if the given parameter is palindrome or n
168171

169172

170173

171-
def even_or_odd(data):
174+
def even_or_odd(data:'int'):
172175
try :
173176
if data%2==0:
174177
return 'even'
@@ -181,7 +184,7 @@ def even_or_odd(data):
181184

182185
#Linked list
183186

184-
def create_node(data):
187+
def create_node(data:'int')->'Linked list':
185188
class node:
186189
def __init__(self,data):
187190
self.data=data
@@ -191,15 +194,15 @@ def __init__(self,data):
191194
return a
192195
# to link a node with another node
193196

194-
def node_link(a,b):
197+
def node_link(a:'int',b:'int'):
195198
a.next=b
196199
b.next=None
197200
#a=node(data1)
198201

199202

200203
# to count number of nodes
201204

202-
def count_node(head):
205+
def count_node(head:'node')->'int':
203206
if head is None:
204207
return 0
205208
else:
@@ -212,7 +215,7 @@ def count_node(head):
212215

213216
# to diplay a linked list whose header node is passed as an argument
214217

215-
def display_nodes(head):
218+
def display_nodes(head:'node')->'int':
216219
t=head
217220
while t is not None:
218221
print(t.data,"->",end="")
@@ -222,21 +225,21 @@ def display_nodes(head):
222225

223226
# Matrix problems
224227

225-
def matrix_add(array1,array2):
228+
def matrix_add(array1:'array',array2:'array')->'array':
226229
import numpy as np
227230

228231
result=np.array(array1)+np.array(array2)
229232
return result
230233

231234

232-
def matrix_sub(array1,array2):
235+
def matrix_sub(array1:'array',array2:'array')->'array':
233236
import numpy as np
234237

235238
result=np.array(array1)-np.array(array2)
236239
return result
237240

238241
# Multiplication of two
239-
def matrix_mul(matrix1,matrix2):
242+
def matrix_mul(matrix1:'array',matrix2:'array')->'array':
240243
import numpy as np
241244
matrix1=np.array(matrix1) # converting list into array
242245
matrix2=np.array(matrix2)
@@ -268,15 +271,15 @@ def matrix_mul(matrix1,matrix2):
268271
for j in i:
269272
sum1=0
270273
for c in j:
271-
sum1=sum1+c # sum all the element of each row each column
274+
sum1=sum1+c # sum all the element of each row each column
272275
zz.append(sum1)
273276
l.append(zz) # appending the sum of each row and column of result matrix into a list
274277
l=np.array(l) # convert the list of result matrix into array
275278
return l
276279

277280

278281

279-
def matrix_shape(matrix1):
282+
def matrix_shape(matrix1:'array')->'list':
280283
import numpy as np
281284
matrix1=np.array(matrix1)
282285
a=list(matrix1.shape)
@@ -289,7 +292,7 @@ def matrix_shape(matrix1):
289292

290293

291294

292-
def matrix_transpose(matrix1):
295+
def matrix_transpose(matrix1:'array')->'array':
293296
import numpy as np
294297
matrix1=np.array(matrix1) # converting list into array
295298
a=list(matrix1.shape) # getting the shape of the array
@@ -302,7 +305,7 @@ def matrix_transpose(matrix1):
302305
t=np.array(tt) # get a transpose of matrix1
303306
return t
304307

305-
def remove_punctuation(my_str):
308+
def remove_punctuation(my_str:'str')->'str':
306309
punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
307310
# remove punctuations from the string
308311
no_punct = ""
@@ -313,7 +316,7 @@ def remove_punctuation(my_str):
313316
#return no_punct
314317
return no_punct
315318

316-
def count_vowels(ip_str):
319+
def count_vowels(ip_str:'str')->'int':
317320
# string of vowels
318321
vowels = 'aeiou'
319322
# make it suitable for comparisions
@@ -330,4 +333,3 @@ def count_vowels(ip_str):
330333
#return the count dictionary
331334
return count
332335

333-

0 commit comments

Comments
 (0)