-
Notifications
You must be signed in to change notification settings - Fork 2
/
functions.py
50 lines (36 loc) Β· 885 Bytes
/
functions.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
"""
Functions
def function_name(argument1, argument2, argument3, ...):
code
return val1, val2, val3 ... (not compulsory)
having arguments is also not compulsory
"""
def hello():
print('hello')
def helloWorld(name):
print('hello ' + name)
def factorial(n):
product = 1
for i in range(1, n + 1):
product *= i
return product
def permutation(n, r): # nPr = n! / (n - r)!
return factorial(n) // factorial(n - r)
def combination(n, r): # nCr n! / r! * (n - r)! --> nPr / r!
return permutation(n, r) // factorial(r)
# a = 10
# hello()
# hello()
# hello()
# helloWorld('john doe')
# helloWorld('anish')
# print(factorial(0))
# print(factorial(4))
# print(factorial(5))
# val = factorial(10)
# print(val + 78)
print(combination(4, 0))
print(combination(4, 1))
print(combination(4, 2))
print(combination(4, 3))
print(combination(4, 4))