Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs1-24fa
lecture-code
Commits
1dd4c228
Commit
1dd4c228
authored
5 months ago
by
Adam Blank
Browse files
Options
Download
Email Patches
Plain Diff
autocommit
parent
64cf0964
master
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
08/jokes.py
+40
-0
08/jokes.py
with
40 additions
and
0 deletions
+40
-0
08/jokes.py
0 → 100644
View file @
1dd4c228
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
=
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
))
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help