Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pyfiglet import Figlet
- from termcolor import colored
- from random import randint
- import requests
- f = Figlet(font="standard")
- print(colored(f.renderText("Dad Jokes 3000"), color="cyan"))
- while True:
- print()
- topic = input("Let me tell you a joke!! Give me a topic: ")
- print()
- url = "https://icanhazdadjoke.com/search"
- r = requests.get(
- url,
- headers={"Accept": "application/json"},
- params={"term": topic}
- )
- data = r.json()
- if not data["results"]:
- print(f"Sorry, I don't have any jokes about {topic}! Please Try again.")
- elif len(data["results"]) == 1:
- print(f"I've got one joke about {topic}. Here it is:")
- print(data["results"][0]["joke"])
- else:
- print("I've got {} jokes about {}. Here's one:".format(len(data["results"]), topic))
- jks = data["results"][randint(0, len(data["results"]))]["joke"]
- print(jks)
- print()
- again = input("Do you want to continue? ").lower().startswith("y")
- if not again:
- print("Goodbye!")
- break
Advertisement
Add Comment
Please, Sign In to add comment