Back to questions
JuniorTheoryCommon
What does the program print?
def price(amount, discount=0, tax=20):
return amount - discount + tax
print(price(100, tax=0), price(100, 5))100 115
- Expecting
5to go totax, the parameter after it in the call: positional arguments fill parameters left to right, so5becomesdiscount. - Expecting a
TypeErrorfor skippingdiscount: a keyword argument setstaxby name, anddiscountkeeps its default0.
- How would you call
priceto pass onlydiscountand keep the defaulttax? - Why does
price(amount=100, 5)fail before the program runs?