Skip to content
← Back to Community
Simple Chat Bot [Beginner Level, Python]
Profile icon
ChristianThone

What is a chatbot?

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.

How do we start building a chatbot?

Simple! We need some variables to store some information. Please define the following(in main.py):

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 main.py:

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

str.lower()

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.

This file cannot be displayed: https://storage.googleapis.com/replit/images/1551136096804_1af567723e8d36eb01c1b36bace57cbf.pn

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:

This file cannot be displayed: https://storage.googleapis.com/replit/images/1551142242435_8cc78c3ff8414f02cd6ea68e03d50acd.pn

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.

Keep coding,
Christian Thone
@ChristianThone

Voters
Profile icon
MICHELLECAPILLA
Profile icon
Progamer092
Profile icon
AshutoshDas4
Profile icon
KrishnaSarvepal
Profile icon
fauziahchan
Profile icon
NabilaNurfatkhi
Profile icon
thelazerpotaos
Profile icon
alishaaline
Profile icon
AmaanSyed2
Profile icon
munaznotfound
Comments
hotnewtop
Profile icon
muffinman12345

How do I make it AI?

Profile icon
Muhammadzakirha
Profile icon
muffinman12345

@Muhammadzakirha I wasn't expecting that answer, but I'll take that as a "No, you cannot make it AI."

Profile icon
Python4Shloka

Thank you this was helpful.

Profile icon
PYer

In A Slightly More Advanced ChatBot [Intermediate, Python], make it so that it scans messages for keywords instead.

Profile icon
ChristianThone

@PYer Hey yea, that is gonna be for my "An Advanced ChatBot [Advanced, Python]", I'm writing A Slightly More Advanced ChatBot [Intermediate, Python] right now!

Profile icon
ChristianThone

@PYer Alright A Slightly More Advanced ChatBot [Intermediate, Python] is out now! Go check it out here. And please let me know if you want more tutorials just like this one, I'll be glad to know what you want to learn about!