Commit 64cf0964 authored by Adam Blank's avatar Adam Blank
Browse files

autocommit

parent c489b055
Showing with 40 additions and 0 deletions
+40 -0
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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment