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
from joke_types import Joke
from joke_library import get_n_jokes, rate_joke, tell_joke
def get_average_joke_rating(ratings: dict[int, int]):
return ...
def find_best_joke(jokes: dict[int, Joke], joke_ratings: dict[int, int]):
best_joke_id: int = -1
...
return jokes_by_id[best_joke_id]
def tell_jokes(n: int = 3):
jokes = get_n_jokes(n)
# Make a dictionary of jokes keyed by id
jokes_by_id: dict[int, Joke] = {}
...
ratings: dict[int, int] = {}
# Tell each joke, going in reverse order, and rate and store user ratings
while len(jokes) > 0:
...
print()
return jokes_by_id, ratings
jokes_by_id, joke_ratings = tell_jokes()
print()
print("The average rating you gave was..." +
str(get_average_joke_rating(joke_ratings)))
print("The best joke was...")
tell_joke(find_best_joke(jokes_by_id, joke_ratings))