-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10_functions.py
More file actions
74 lines (54 loc) · 1.29 KB
/
10_functions.py
File metadata and controls
74 lines (54 loc) · 1.29 KB
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
# Question No 1.
def square_of_num(number):
return number ** 2
result = square_of_num(4)
print(result)
# Question No 2.
def add(numOne, numTwo):
return numOne + numTwo
print(add(5, 5))
# Question No 3.
def multiply(p1, p2):
return p1 * p2
print(multiply(8, 5))
print(multiply('a', 5))
print(multiply(5, "h"))
# Question No 4.
import math
def circle_stats(radius):
area = math.pi * radius ** 2
circumFerence = 2 * math.pi * radius
return area, circumFerence
a, c = circle_stats(3)
print("Area:", a, "CircumFerence:", c)
# Question No 5.
def greet(name):
return "Hello, " + name + " !"
print(greet("Waseem"))
# Question No 6.
cube = lambda x: x ** 3
print(cube(3))
# Question No 7.
def sum_all(*args):
return sum(args)
print(sum_all(1, 2))
print(sum_all(1, 2, 3, 4, 5))
print(sum_all(1, 2, 3, 4, 5, 6, 7, 8))
# Question No 8.
def print_kwargs(**kwargs):
for key, value in kwargs.items():
print(f"{key} : {value}")
print_kwargs(name="waseem akram", power="lazer", enemy="Dr.jackaal")
# Question No 9.
def even_generator(limit):
for i in range(2, limit + 1, 2):
yield i
for num in even_generator(10):
print(num)
# Question No 10.
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)
print(factorial(5))