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
def list_has_duplicate(l):
"""Returns True exactly when `l` has at least one duplicate and False otherwise"""
# Fill this in!!
def sides_are_not_duplicated(die):
"""
Returns True when the provided `die` does not have any sides with the exact same value
and False otherwise.
Hint: You will want to use `list_has_duplicate` as a helper!
"""
vals = []
for x in die:
vals.append(x.value)
return not list_has_duplicate(vals)
def probabilities_add_to_1(die):
"""
Returns True exactly when the probabilities of the sides that make up `die`
add up to "nearly" 1 and False otherwise.
"""
total = 0
# Fill in code here!
return within(total, 1, 0.00001)
def is_valid_die(die):
return sides_are_not_duplicated(die) and probabilities_add_to_1(die)
def within(x, y, delta):
return abs(x - y) < delta
def check_die(die, outcome):
if is_valid_die(die) != outcome:
if outcome:
print("Your code incorrectly claims", die, "is an INVALID die!")
else:
print("Your code incorrectly claims", die, "is a VALID die!")
exit(1)