Python practice: Defining Functions & Return Values
Chapter 13 · 8 questions · included in full access
Question 1 · easy
Define sales commission function
Solve it in your browserDefine function
calc_commission(sales, rate)that returnssales * rate. Call it with10000, 0.12and print the result:Question 2 · easy
Function with return value
Solve it in your browserDefine function
add_gst(amount)that returnsround(amount * 1.18, 2). Call it with500and print the result:Question 3 · easy
Return multiple values as tuple
Solve it in your browserDefine
calc_financials(rev, cost)that returnsrev - cost, (rev - cost) / rev. Unpack intoprofit, marginfor50000, 35000. Printprofiton line 1 andmarginon line 2:Question 4 · easy
Currency formatter function with docstring
Solve it in your browserDefine
format_inr(amount)with docstring"""Format as INR."""that returnsf"₹{amount:,.2f}". Call with12500and print:Question 5 · easy
Unit cost calculator function
Solve it in your browserDefine
unit_cost(total_cost, units)that returnsround(total_cost / units, 2). Call with14500, 25and print:Question 6 · easy
Check weekend function
Solve it in your browserDefine
is_weekend(day)returningTrueifday in ["Saturday", "Sunday"], elseFalse. Call with"Sunday"and print:Question 7 · medium
Discount threshold function
Solve it in your browserDefine
get_discount(units)returning0.15ifunits >= 20,0.10ifunits >= 10, else0.0. Call with15and print:Question 8 · medium
Net revenue after tax and cost function
Solve it in your browserDefine
net_payout(gross, tax_rate, fee)that returnsround(gross * (1 - tax_rate) - fee, 2). Call with10000, 0.18, 500and print:
These questions are part of full access.
The first chapters of every track are free. Full access is a one-time payment.
See pricing