Sort three numbers X20321


Statement
 

pdf   zip

html
  1. Design a function ordena3(a, b, c) which, given three values returns them sorted. This function must be solved with all necessary if analyzing all possible cases: when a is greater than b and c, when b is greater than a and c, and so on.
  2. Design a function ordena2(a, b) that given two values returns them sorted.
  3. Design a function ordena3_2a2(a, b, c) that given three values returns them sorted. This function cannot contain any if and must be solved calling function ordena2(a, b) from previous point.

Scoring

The first two points are worth 30 points. The last one is worth 40 points.

Sample session
>>> ordena3('c', 'b', 'a')
('a', 'b', 'c')
>>> ordena3(1, 2, 1)
(1, 1, 2)
>>> ordena2('d', 'b')
('b', 'd')
>>> ordena2(1, 1)
(1, 1)
>>> ordena3_2a2('c', 'b', 'a')
('a', 'b', 'c')
>>> ordena3_2a2(1, 2, 1)
(1, 1, 2)
Information
Author
InfBesos
Language
English
Translator
Original language
Catalan
Other languages
Catalan Spanish
Official solutions
Python
User solutions
Python