Skip to content

Commit fbaf99e

Browse files
committed
Codes 4 W04
1 parent b9a4fec commit fbaf99e

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

Week04/functions.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
def fn(arg1: int = 0, arg2: int = 0, *, arg3: int = 1) -> int:
2+
"""This function sums two numbers."""
3+
if type(arg1) != int:
4+
raise TypeError("Wrong type!")
5+
return int(arg1 + arg2)
6+
7+
8+
try:
9+
print(fn(3.5, 5))
10+
except TypeError:
11+
print("arg1 is wrong typed")
12+
13+
14+
print(fn(3, 5, arg3=7))

Week04/nested.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def parent():
2+
def nested():
3+
print("Nested")
4+
5+
parent.external_nested = nested
6+
7+
print("Parent")
8+
9+
10+
parent()
11+
parent.external_nested()

Week04/sequences.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
a_list = [1, 3, 5, 7]
2+
a_list.append(9)
3+
print(a_list)
4+
a_list.insert(2, 4)
5+
print(a_list)

0 commit comments

Comments
 (0)