Common Mistakes
Week 4,5 - Conditionals and Loops
1. Conditional pathways
If you are using a conditional structure such as if...elif...else, make sure that your computation follows the correct path and that you have more than one path to check if the condition is not satisfied with else.
For match case, you need to make sure that there is a case _ that follows the unmet condition path. This works as else argument in if conditionals.
2. Arguments of range()
Remember that the built-in function range() can take multiple arguments.
If it takes a single one then it starts counting from 0 and it loops that many times:
range(5) #--> [0,1,2,3,4]
If it takes 2 arguments then it loops for the amount in between the given arguments. Remember these arguments are (inclusive, exclusive), respectively:
range(3,7) #--> [3,4,5,6]
If it takes 3 arguments, it loops for the amount in between the first two numbers, and the last argument is used for the interval of iteration:
range(11,17,2) #--> [11,13,15]
You can also have negative iterations (see your lecture notes):
range(7,2,-2) #--> [7,5,3]