Skip to content

Commit b6d88dc

Browse files
committed
Feat: Added the missing exercises.
1 parent 1e84208 commit b6d88dc

3 files changed

Lines changed: 38 additions & 0 deletions

File tree

prep-exercises/double-exercise.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
def half(value):
2+
return value / 2
3+
4+
def double(value):
5+
return value * 2
6+
7+
def second(value):
8+
return value[1]
9+
10+
11+
print(half(22))
12+
print(half("hello"))
13+
print(half("22"))
14+
15+
16+
print(double(22))
17+
print(double("hello"))
18+
print(double("22"))
19+
20+
print(second(22))
21+
print(second(0x16))
22+
print(second("hello"))
23+
print(second("22"))
24+
25+
# I expected the double("22"), my prediction was wrong, I expected that it will behave like javascript (smart enough to convert it to number but risky)
26+
# however python will not change type to int and will just double the string ("2222"), because python is strongly typed.

prep-exercises/limit-types.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def double(number):
2+
return number * 3
3+
4+
print(double(10))
5+
6+
# The bug is that method naming(double), as this method is multiplying the number by 3, should be named triple, to make sense of the method scope,
7+
# and show other developers what is the purpose of it even before reading the code.
8+
# Or we can change the multiplied by number from 3 to 2 to match the correct meaning of the method.

prep-exercises/methods.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
# this is similar to new Date() object in js, but only getting the date not hours etc.
44

5+
# The core method advantages over free functions:
6+
# 1. Methods belong to a class, preventing naming conflicts with other parts of our program.
7+
# 2. Method syntax like car.drive() reads naturally like a noun performing an action, making code easier to follow
8+
# 3. Different classes can use the exact same method name to perform distinct, specialized actions.
59
class Person:
610
def __init__(self, name: str, preferred_os: str, dob: dt.date):
711
self.name = name

0 commit comments

Comments
 (0)