-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset_range2.py
More file actions
46 lines (34 loc) · 962 Bytes
/
set_range2.py
File metadata and controls
46 lines (34 loc) · 962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# The range of a set of values is the maximum value minus the minimum
# value. Define a procedure, set_range, which returns the range of three input
# values.
# Hint: the procedure, biggest which you coded in this unit
# might help you with this question. You might also like to find a way to
# code it using some built-in functions.
def bigger(a, b):
if a > b:
return a
else:
return b
def biggest(a, b, c):
return bigger(a, bigger(b, c))
def set_range(a, b, c):
big = biggest(a, b, c)
if big == a:
if b > c:
return a - c
else:
return a - b
if big == b:
if a > c:
return b - c
else:
return b - a
if big == c:
if a > b:
return c - b
else:
return c - a
print set_range(10, 4, 7)
# >>> 6 # since 10 - 4 = 6
print set_range(1.1, 7.4, 18.7)
# >>> 17.6 # since 18.7 - 1.1 = 17.6