Skip to content
GitLab
Menu
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
64cf0964
Commit
64cf0964
authored
6 months ago
by
Adam Blank
Browse files
Options
Download
Email Patches
Plain Diff
autocommit
parent
c489b055
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
08/joke_library.py
+40
-0
08/joke_library.py
with
40 additions
and
0 deletions
+40
-0
08/joke_library.py
0 → 100644
View file @
64cf0964
import
time
import
requests
from
joke_types
import
*
def
tell_joke
(
joke
:
Joke
)
->
None
:
print
(
"Telling a "
+
joke
[
"type"
]
+
" joke..."
)
if
joke
[
"type"
]
==
'knock-knock'
:
for
line
in
joke
[
"setup"
].
split
(
"
\n
"
):
print
(
line
)
time
.
sleep
(
1
)
else
:
print
(
joke
[
"setup"
])
time
.
sleep
(
1
)
print
(
joke
[
"punchline"
])
def
rate_joke
(
joke
:
Joke
)
->
int
:
numerical_rating
:
int
=
-
1
while
0
>
numerical_rating
or
numerical_rating
>=
5
:
rating
=
input
(
"Rate that joke on a scale from 0-4: "
)
if
rating
.
isnumeric
():
numerical_rating
=
int
(
rating
)
return
numerical_rating
def
get_one_joke
(
type
:
JokeType
=
"any"
)
->
Joke
:
if
type
==
"any"
:
return
requests
.
get
(
"http://labradoodle.caltech.edu:3005/jokes/random"
).
json
()
else
:
return
requests
.
get
(
"http://labradoodle.caltech.edu:3005/jokes/"
+
type
+
"/random"
).
json
()[
0
]
def
get_n_jokes
(
n
:
int
,
type
:
JokeType
=
"any"
)
->
list
[
Joke
]:
jokes
:
list
[
Joke
]
=
[]
...
assert
len
(
jokes
)
==
n
return
jokes
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