Skip to content

Commit 1ae7aab

Browse files
committed
Add why_we_use_types.py exercise with bug identification and fix
- Add exercise demonstrating the importance of type hints - Include buggy double() function that multiplies by 3 instead of 2 - Document the bug and propose two possible fixes
1 parent c54ba92 commit 1ae7aab

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

prep/why_we_use_types.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Question
2+
3+
def double(number):
4+
return number * 3
5+
6+
print(double(10))
7+
8+
# Read the above code and write down what the bug is. How would you fix it?
9+
10+
11+
# Answer
12+
# The bug: The function multiplies the number by 3 instead of 2, which contradicts its name.
13+
14+
# Proposed fix: We can either change the function implementation so that it returns number * 2 or we change the function name to 'triple'

0 commit comments

Comments
 (0)