Python practice: Defining Functions & Return Values

Chapter 13 · 8 questions · included in full access

  1. Question 1 · easy

    Define sales commission function

    Define function calc_commission(sales, rate) that returns sales * rate. Call it with 10000, 0.12 and print the result:

    Solve it in your browser
  2. Question 2 · easy

    Function with return value

    Define function add_gst(amount) that returns round(amount * 1.18, 2). Call it with 500 and print the result:

    Solve it in your browser
  3. Question 3 · easy

    Return multiple values as tuple

    Define calc_financials(rev, cost) that returns rev - cost, (rev - cost) / rev. Unpack into profit, margin for 50000, 35000. Print profit on line 1 and margin on line 2:

    Solve it in your browser
  4. Question 4 · easy

    Currency formatter function with docstring

    Define format_inr(amount) with docstring """Format as INR.""" that returns f"₹{amount:,.2f}". Call with 12500 and print:

    Solve it in your browser
  5. Question 5 · easy

    Unit cost calculator function

    Define unit_cost(total_cost, units) that returns round(total_cost / units, 2). Call with 14500, 25 and print:

    Solve it in your browser
  6. Question 6 · easy

    Check weekend function

    Define is_weekend(day) returning True if day in ["Saturday", "Sunday"], else False. Call with "Sunday" and print:

    Solve it in your browser
  7. Question 7 · medium

    Discount threshold function

    Define get_discount(units) returning 0.15 if units >= 20, 0.10 if units >= 10, else 0.0. Call with 15 and print:

    Solve it in your browser
  8. Question 8 · medium

    Net revenue after tax and cost function

    Define net_payout(gross, tax_rate, fee) that returns round(gross * (1 - tax_rate) - fee, 2). Call with 10000, 0.18, 500 and print:

    Solve it in your browser

These questions are part of full access.

The first chapters of every track are free. Full access is a one-time payment.

See pricing