preface

Hello everyone, I am Jiejie, today I will teach you how to develop your own chatbot in Python, Python language can do it, and only needs 11 lines of code.

I. Project ideas

Writing a simple chatbot in Python is not difficult because Python has a rich open source library that can control wechat to receive/send messages.

It needs to call the interface of the Turing robot, and conduct personal authentication after registering at http:// www.turingapi.com/. You can use 100 of them for free every day.

Select “API Access” from “Robot Settings”, run the code first when using, copy the APIKey to the terminal, press Enter to continue running, and then you can start chatting.

Second, the environment

Operating system: MacOSX

Editor: PyCham

Python version: 3.7.4

Related modules:

import requests

import re

Three, code implementation

First, import the required related modules.

import request
import re
Copy the code

You need to register the Turing robot, apply for a Key, run it and enter it.

Key = input('\n enter your key: ')Copy the code

Start the dialog operation, and finally run the relevant information to complete.

Isn’t that easy? All it takes is 11 lines of code.

Iv. Achievements Display

Now, let’s start the chatbot and enter the requested key.

\

Then you can chat with yourself, the robot is omniscient, omniscient oh!

\

The end of the

Now you know how to get a simple chatbot? It’s cute, it’s funny, it’s informative, it’s always there when you need it, it’s Python magic.

Do you think Python is fun?

Hopefully you’ll soon learn Python and do what you love most with it!