8. Software Development
Activity 22: Debugging Sample Python Code for an Application
Solution:
- First, you need to copy the source code, as demonstrated in the following code snippet:
DEFAULT_INITIAL_BASKET = ["orange", "apple"] def create_picnic_basket(healthy, hungry, initial_basket=DEFAULT_INITIAL_BASKET): basket = initial_basket if healthy: basket.append("strawberry") else: basket.append("jam") if hungry: basket.append("sandwich") return basket
For the first step, the code creates a list of food that is based on an initial list that can be passed as an argument. There are then some flags that control what gets added. When
healthy
is true, a strawberry...