MikeWP

Untitled

Mar 19th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. from pyfiglet import Figlet
  2. from termcolor import colored
  3. from random import randint
  4. import requests
  5.  
  6.  
  7. f = Figlet(font="standard")
  8. print(colored(f.renderText("Dad Jokes 3000"), color="cyan"))
  9.  
  10. while True:
  11.     print()
  12.     topic = input("Let me tell you a joke!! Give me a topic: ")
  13.     print()
  14.     url = "https://icanhazdadjoke.com/search"
  15.     r = requests.get(
  16.         url,
  17.         headers={"Accept": "application/json"},
  18.         params={"term": topic}
  19.     )
  20.     data = r.json()
  21.  
  22.     if not data["results"]:
  23.         print(f"Sorry, I don't have any jokes about {topic}! Please Try again.")
  24.     elif len(data["results"]) == 1:
  25.         print(f"I've got one joke about {topic}. Here it is:")
  26.         print(data["results"][0]["joke"])
  27.     else:
  28.         print("I've got {} jokes about {}. Here's one:".format(len(data["results"]), topic))
  29.         jks = data["results"][randint(0, len(data["results"]))]["joke"]
  30.         print(jks)
  31.     print()
  32.     again = input("Do you want to continue? ").lower().startswith("y")
  33.     if not again:
  34.         print("Goodbye!")
  35.         break
Advertisement
Add Comment
Please, Sign In to add comment