Back to Lesson
Keyword-Only Mandates
Execute positional override barriers cleanly locking configuration strings tightly.
Instructions
- Given function signature. The
def apply_discount(price, *, discount=0.10):strictly isolates any following entries ensuring explicit keys.* - Your function should compute and return.
price - (price * discount) - If somebody runs, it instantly raises a TypeError because they missed writing
apply_discount(100, 0.20).discount=0.20 - Uselogic handling this: attempt
try, and exceptapply_discount(100, 0.20)catching it by printingTypeError."Must specify keyword"
main.py
main.py
Ctrl + Enter