二手产品经理

二手产品经理

THIS IS RENO

json - 91 days - Learn Python online for 100 days

Record#

  1. Continue studying the points of request and json today.
  2. Use the headers={"Accept":"application/json"} parameter to specify the format of the returned content.
  3. Today's exercise is to get and display a joke from [icanhazdadjoke](https://icanhazdadjoke.com/), and ask the user if they want to save or perform the next operation.

CODE#

main.py#

import requests, json
from replit import db

while True:
  result = requests.get("https://icanhazdadjoke.com/",
                        headers={"Accept": "application/json"})

  joke = result.json()
  id = joke["id"]
  text = joke["joke"]
  print(text)
  print()
  menu = input("(s)ave joke, (l)oad old jokes, (n)ew joke\n")
  if menu == "s":
    db[id] = {"joke": text}
  elif menu == "l":
    for key in db.keys():
      print(db[key]["joke"])
      print()

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.