Skip to content

Commit d025557

Browse files
committed
Adding Subprogram
1 parent ac07da8 commit d025557

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

Python/Subprogram/exp.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
rectangle = lambda length, width: length * width
2+
3+
print(rectangle(length = 5, width = 5))
4+
5+
name = "Billy"

Python/Subprogram/main.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import exp
2+
3+
# positional or Keyword parameter
4+
def rectangle (length, width):
5+
return length * width
6+
7+
print(rectangle(length = 10, width = 5))
8+
9+
# positional only parameter
10+
def addition (a, b, /):
11+
return a + b
12+
13+
print(addition(10, 5))
14+
15+
# keyword only parameter
16+
def greeting (*, name):
17+
return f"Hello, {name}!"
18+
19+
print(greeting(name = "Fenny"))
20+
21+
# variadic positional parameter
22+
def calculation(*args):
23+
print(type(args))
24+
25+
total = sum(args)
26+
27+
return total
28+
29+
print(calculation(10, 20, 30, 40, 50))
30+
31+
# variadic keyword parameter
32+
def print_info(**kwargs):
33+
info = ""
34+
35+
for key, value in kwargs.items():
36+
info += key + ': ' + value + ", "
37+
38+
return info
39+
40+
print(print_info(name = "Fenny", age = "28", city = "Tanjung Redeb", country = "Indonesia"))
41+
42+
print(exp.rectangle(length = 10, width = 5))
43+
44+
print(exp.name)

Python/Subprogram/test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def minimum(a, b):
2+
if a < b:
3+
return a
4+
else:
5+
return b
6+
7+
print(minimum(10, 5))
8+
9+
def data(name, age):
10+
print("Name:", name)
11+
print("Age:", age)
12+
13+
data(name="Billy", age=20)

0 commit comments

Comments
 (0)