§ 1.12section 12 of 16·~3 min
Check your understanding
- Why does
"5" + 5fail, and what are two ways to fix it? - You committed but your friend can't see the change on GitHub. Why?
- What's the difference between
returnandprintinside a function? - When would you pick a set instead of a list?
- What does
totals.get(cat, 0) + amountdo on the first expense of a new category?
Answers
- You can't add a
strand anint. Useint("5") + 5→10, or"5" + str(5)→"55". - You didn't
git push. A commit is only local until you push it. returnhands a value back to the calling code, whileprintonly shows text on the screen and gives backNone.- When you need unique items or fast "is it in here?" checks, and you don't care about order.
- The category isn't in
totalsyet, so.getreturns0and the new total is simply the amount.
Now take the quiz. The pass mark is 7/10.
LABAIE-101· hands-on
Expense summary shows ₹0
Fix a real ticket in a small codebase you didn't write: read the code, change only the functions you're given, pass the tests, then submit for hidden checks and a score.
Open the lab →