Skip to content

Exercises

Exercise 1 — Default arguments

Expose scale(x, factor=1.0) and demonstrate calling it with and without factor.

Success criteria:

  • scale(2.0) returns 2.0
  • scale(2.0, factor=3.0) returns 6.0

Exercise 2 — Return a pair

Write minmax(list_of_numbers) returning (min, max).

Success criteria:

  • minmax([3,1,2]) == (1,3)

Hint:

  • use std::minmax_element.

Exercise 3 — Raise an exception

Modify minmax so it throws if the input vector is empty.

Success criteria:

  • calling minmax([]) raises a Python exception with a useful message.