Back to Lesson

Keyword-Only Mandates

Execute positional override barriers cleanly locking configuration strings tightly.

Instructions

  • Given function signature
    def apply_discount(price, *, discount=0.10):
    . The
    *
    strictly isolates any following entries ensuring explicit keys.
  • Your function should compute and return
    price - (price * discount)
    .
  • If somebody runs
    apply_discount(100, 0.20)
    , it instantly raises a TypeError because they missed writing
    discount=0.20
    .
  • Use
    try
    logic handling this: attempt
    apply_discount(100, 0.20)
    , and except
    TypeError
    catching it by printing
    "Must specify keyword"
    .
main.py
main.py