Python初学者好玩案例(二):听两个聊天机器人互相聊天(15行代码)

无聊的时候,可以听两个聊天机器人互相聊天,可以自己输入一个话题,然后打开沉默,静静的无聊。代码很简单,也就不解释了。
from time import sleep
import requests
s = input(“请主人输入话题:”)
while True:
resp = requests.post(http://www.tuling123.com/openapi/api“,data={“key”: “4fede3c4384846b9a7d0456a5e1e2943”, “info”: s, })
resp = resp.json()
sleep(1)
print(‘小鱼:’, resp[‘text’])
s = resp[‘text’]
resp = requests.get(“http://api.qingyunke.com/api.php“, {‘key’: ‘free’, ‘appid’: 0, ‘msg’: s})
resp.encoding = ‘utf8’
resp = resp.json()
sleep(1)
print(‘菲菲:’, resp[‘content’])

    原文作者:万能的老J
    原文地址: https://www.jianshu.com/p/39875fddcfec
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞