Skip to content

Commit 3196be3

Browse files
committed
Add functions to demonstrate basic operations and concepts in Python
1 parent 5eaa985 commit 3196be3

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

10_functions/10_functions.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Question No 1.
2+
def square_of_num(number):
3+
return number ** 2
4+
5+
result = square_of_num(4)
6+
print(result)
7+
8+
# Question No 2.
9+
def add(numOne, numTwo):
10+
return numOne + numTwo
11+
12+
print(add(5, 5))
13+
14+
# Question No 3.
15+
def multiply(p1, p2):
16+
return p1 * p2
17+
18+
print(multiply(8, 5))
19+
print(multiply('a', 5))
20+
print(multiply(5, "h"))
21+
22+
# Question No 4.
23+
import math
24+
def circle_stats(radius):
25+
area = math.pi * radius ** 2
26+
circumFerence = 2 * math.pi * radius
27+
return area, circumFerence
28+
29+
a, c = circle_stats(3)
30+
print("Area:", a, "CircumFerence:", c)
31+
32+
# Question No 5.
33+
def greet(name):
34+
return "Hello, " + name + " !"
35+
36+
print(greet("Waseem"))
37+
38+
# Question No 6.
39+
cube = lambda x: x ** 3
40+
print(cube(3))
41+
42+
# Question No 7.
43+
def sum_all(*args):
44+
return sum(args)
45+
46+
print(sum_all(1, 2))
47+
print(sum_all(1, 2, 3, 4, 5))
48+
print(sum_all(1, 2, 3, 4, 5, 6, 7, 8))
49+
50+
# Question No 8.
51+
def print_kwargs(**kwargs):
52+
for key, value in kwargs.items():
53+
print(f"{key} : {value}")
54+
55+
print_kwargs(name="waseem akram", power="lazer", enemy="Dr.jackaal")
56+
57+
# Question No 9.
58+
def even_generator(limit):
59+
for i in range(2, limit + 1, 2):
60+
yield i
61+
62+
for num in even_generator(10):
63+
print(num)
64+
65+
# Question No 10.
66+
def factorial(n):
67+
if n == 0:
68+
return 1
69+
else:
70+
return n * factorial(n - 1)
71+
72+
print(factorial(5))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy