Skip to content

Commit cf12c0a

Browse files
committed
Completed "Why we use types" exercises.
1 parent 3f26722 commit cf12c0a

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def double(value):
2+
return value * 2
3+
4+
# I predict that double("22") will produce 22.0
5+
6+
result = double("22")
7+
print(result) # Actual result is 2222
8+
9+
# This is because the string is duplicated twice, "22" + "22" = "22" * 2, it is repeating the a sequence of string.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def double(number):
2+
return number * 3
3+
4+
print(double(10))
5+
6+
# There are two possible ways to fix the bug.
7+
8+
# 1. The function name is wrong, it needs to be named to triple
9+
# 2. Or the function name is correct but the calculation is wrong, it should be return * 2
10+
11+
def double(number):
12+
return number * 2
13+
14+
value = 10
15+
print(double(value))

0 commit comments

Comments
 (0)