Simple Chat Bot [Beginner Level, Python]
A chat bot can be defined in many ways, I define it as a program designed and developed to keep the user entertained. Mayhap you define it differently that doesn't matter, what matters is that we are gonna build a simple one today; Before we start, I will be assuming that you have a basic understanding of Python 3.0. If not then I think you should learn it before reading the rest of this tutorial or you will get confused.
Simple! We need some variables to store some information. Please define the following(in
UserInput = "" ChatBot_Name = "Ozzi"
There, now we have a few variables and two lines of code!!!
Let's not get too excited though, we still have quite a bit to do. Feel free to name your chatbot whatever you would like, I have named mine "Ozzi". Now for the fun part, collecting User Input to reference later. Write the following into
UserInput = str.lower(input(": "))
This will store the user input to our variable,
UserInput. We will refrence this soon. You can see that I wrote
this will make the User Input into all lower case letters, that way we don't have to check for all possible combinations of UPPER CASE and lowercase letters. Now we want the chat bot to talk dont we??? YES! So let's give it a small brain so it can answer the user when the input "Hi". So in
main.py write the following:
if UserInput == "hi": print(ChatBot_Name + ": Hello!")
As you can see here we check if the user says "hi", if this is
python True then we will have the Chat Bot output "Hello". I'll show you an example.
As you can see I said hi to my chat bot and it responded!!!
Now that is a simple thing, lets have it answer a question. Let's ask it something simple. "Who made you?", great question so lets program it like the other part.
elif UserInput == "who made you?": print(ChatBot_Name + ": I was made by Christian Thone") # You can change my name to your name.
Here is the output:
There we go now we have 2 Inputs, that the Chat Bot can can respond too, if you use the same method for all the other new inputsyou wish for your bot to have, you will have a good chat bot that people will love. Stay tuned for
"A Slightly More Advanced ChatBot [Intermediate, Python]", where I will go over how to make a more advanced chat bot, with more variables and better responses.
A Slightly More Advanced ChatBot [Intermediate, Python], make it so that it scans messages for keywords instead.