0% found this document useful (0 votes)
9 views19 pages

Python Entertainment Chatbot Project

Uploaded by

farah sharif
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views19 pages

Python Entertainment Chatbot Project

Uploaded by

farah sharif
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1

Certificate.
This is to certify that Farah Sharif Cherukur has completed the
project file on the topic of AI chatbot under my guidance and
supervision.

I am satisfied with their initiative and efforts for the completion of the
project file as part of the curriculum of CBSE class XII Examination.

Date:
Institution:

Signature of Teacher in charge:

Signature of Examiner:

1
2

Index.
1.​Introduction
2.​Objective
3.​Tools and Technology used
4.​System design and methodology
5.​Source code
6.​Output
7.​Limitations
8.​Conclusion

2
3

Introduction.
Artificial intelligence is used to construct a computer program known as a chatbot that simulates
human chats with users.

It employs a technique known as NLP to comprehend the user’s inquiries and offer pertinent
information. Chatbots have various functions in customer service, information retrieval, and
personal support.

A chatbot is a computer program that simulates conversation with humans. Chatbots are often used in
customer service applications, where they can answer questions and provide support to customers.
Chatbots can also be used for educational purposes, to provide information and answer questions
on a variety of topics.

Applications of Chatbots

●​ Customer service: Many companies are now using chatbots to provide customer support. For
example, the chatbot on the American Airlines website can help customers book flights,
check their flight status, and get answers to common questions.
●​ Education: Chatbots are also being used in education. For example, the chatbot on the
Duolingo website can help students learn new languages.
●​ Sales: Chatbots are also being used in sales. For example, the chatbot on the Drift website
can help sales teams qualify leads and answer questions.
●​ Marketing: Chatbots are also being used in marketing. For example, the chatbot on the
Sephora website can help customers find the right products and make recommendations.
●​ Entertainment: Chatbots are also being used for entertainment. For example, the chatbot on
the Cleverbot website can have conversations with users on a variety of topics.

Main Approaches to the Development of Chatbots

The main approaches to the development of chatbots are as follows:

1.​ Rule-Based Approach:


○​ Trains a chatbot to answer questions based on a list of pre-determined rules on which
it was primarily trained.
○​ These set rules can either be pretty simple or quite complex, and we can use these
rule-based chatbots to handle simple queries, but not process more complicated
requests or queries.
2.​ Self-learning Chatbots:
○​ Self-learning chatbots are chatbots that can learn on their own.
○​ These leverage advanced technologies such as Artificial Intelligence (AI) and
Machine Learning (ML) to train themselves from behaviors and instances.
○​ Generally, these chatbots are quite smarter than rule-based bots.
○​ We can classify the Self-learning chatbots further into two categories:

3
4
○​ Retrieval-Based Models: Based on an input question, these models can obtain
predefined responses from a knowledge base. They evaluate user input and compare
it to the closest equivalent response in the knowledge base.
○​ Generative Models: Generative models create responses from scratch based on the
input query. They employ approaches like sequence-to-sequence models or
transformers, for example, to produce human-like answers.

The chatbot built in this project is a rule-based keyword-matching bot.

4
5

Objective.
1. To Develop an Engaging Python-Based Entertainment Chatbot

The primary objective is to create a fun and interactive chatbot capable of entertaining users through
jokes, fun facts, riddles, playful conversations, and casual chat responses. The bot should simulate a
friendly personality, respond humorously to user queries, and provide light-hearted interactions that
enhance user enjoyment.

2. To Implement Keyword-Based Intent Recognition for Entertainment Features

The chatbot aims to understand user input through simple text processing and keyword matching. It
detects intents such as asking for jokes, riddles, games, facts, greetings, or casual conversation
topics. Based on these intents, it generates creative, varied, and entertaining responses chosen from
predefined lists to keep the interaction lively and engaging.

3. To Demonstrate Practical Use of Python in Building Interactive Entertainment


Systems

The project showcases how Python can be used to build real-time interactive entertainment tools. It
highlights the use of loops, conditionals, string processing, and modular design to create a chatbot
that can entertain users. This reflects real-world applications of entertainment bots in gaming
platforms, social media, and digital assistants.

5
6

Tools and Technology used.


1. Programming Language
Python 3.x

●​ Chosen for its simplicity, readability, and strong support for text-based applications.
●​ Ideal for building interactive programs like entertainment chatbots.

2. Python Libraries / Modules


Since this is a fun, entertainment-focused chatbot, the project uses lightweight and built-in Python
modules:

a) Random

●​ Used to select random jokes, riddles, fun facts, or playful replies.


●​ Helps make responses unpredictable and entertaining.

b) String

●​ Used for text handling, lowercase conversion, and punctuation processing.


●​ Ensures uniform and clean input for keyword matching.

c) Time (Optional)

●​ Adds small delays to simulate natural conversation timing.


●​ Enhances user engagement by making the chatbot feel more lively.

d) Re (Regular Expressions)

●​ Used for simple pattern matching and keyword detection in user input.
●​ Helps identify intents like “tell me a joke,” “fun facts,” “riddle,” etc.​

(Advanced NLP libraries are not required, since this is a rule-based entertainment bot.)

3. Development Environment
Code Editors / IDEs

●​ Visual Studio Code


●​ PyCharm

6
7
●​ Sublime Text
●​ OR the built-in Python IDLE

These provide syntax highlighting and easy execution of the chatbot.

Execution Environment

●​ Terminal / Command Prompt for running the Python script.

4. System Requirements
●​ Works on Windows, macOS, or Linux.
●​ Requires only Python 3.x installed.
●​ No external hardware or advanced libraries needed.

5. Optional Tools (For Future Enhancement)


a) Text-to-Speech Libraries (pyttsx3)

●​ For speaking jokes or riddles aloud.

b) Tkinter or PyQt

●​ To create a GUI-based entertainment bot.

c) NLTK or spaCy

●​ It can be used if you want to add real NLP for smarter entertainment interactions.​

7
8

System Design and Methodology.


1. Architecture Overview
The entertainment chatbot is built using a simple, modular, and rule-based architecture designed to
provide jokes, riddles, fun facts, and casual conversation. The flow of the system is:

User Input → Preprocessing → Intent Detection → Response Selection → Output

a) User Input Layer

●​ Accepts text input from the user through the console.


●​ Acts as the entry point for jokes, riddles, facts, or casual chat requests.

b) Preprocessing Layer

Processes the text to ensure accurate keyword matching:

●​ Converts text to lowercase


●​ Removes unnecessary spaces and punctuation
●​ Splits sentences into words (simple tokenization)

This normalization ensures that different writing styles produce consistent results.

c) Intent Detection Layer

The chatbot identifies what the user wants by:

●​ Matching keywords like joke, riddle, fun fact, bored, game, hello, bye, etc.
●​ Mapping these keywords to predefined entertainment categories (intents).
●​ Selecting the strongest matched intent.​

Examples of intents:

●​ Joke Intent: “tell me a joke,” “make me laugh.”


●​ Riddle Intent: “Give me a riddle,” “ask me something tricky.”
●​ Fun Fact Intent: “fun fact,” “tell me something interesting.”
●​ Casual Chat Intent: “hi,” “what’s up,” “how are you.”
●​ Exit Intent: “bye,” “quit,” “stop.”

d) Response Generation Layer

For each intent, the chatbot contains:

8
9
●​ A list of jokes
●​ A list of riddles
●​ A list of fun facts
●​ Casual or humorous one-liners
●​ Default fallback messages

The chatbot selects a random response from the appropriate list to keep the conversation lively,
varied, and entertaining.

e) Output Layer

●​ Displays the final chatbot response on the console.


●​ Ensures smooth and continuous interaction until the user chooses to exit.

2. Methodology / Workflow
Step 1: Creating the Entertainment Content

●​ Define categories such as jokes, riddles, fun facts, and small talk.
●​ Prepare multiple responses for each category so the bot feels dynamic.

Step 2: Input Processing

●​ Convert the user’s text to lowercase.


●​ Remove punctuation for clearer keyword matching.
●​ Extract meaningful words to detect what type of entertainment the user wants.

Step 3: Intent Classification

●​ Compare user keywords with predefined keyword lists for each intent.
●​ Identify the matching intent (e.g., joke → joke list).
●​ If no intent is detected, use fallback phrases like:
○​ “I didn’t get that. I want to hear a joke instead?”

Step 4: Response Selection

●​ Select a random joke, riddle, or fact from the corresponding list.


●​ Maintain variety so users don’t get the same response repeatedly.

Step 5: Output Delivery

●​ Print the response to the console.


●​ Maintain conversational flow by prompting the user again.

Step 6: Continuous Loop & Error Handling

9
10
●​ The chatbot continues running until the user types an exit keyword.
●​ Includes safeguards to prevent crashes from invalid inputs.​

3. Advantages of This Methodology


a) Simple and Modular Design

●​ Easy to add new jokes, riddles, facts, or conversational lines anytime.


●​ Predefined lists can be expanded without changing core logic.

b) Highly Engaging

●​ Randomized responses keep the conversation fresh and entertaining.


●​ Designed to lighten the mood, reduce boredom, and provide fun interactions.

c) Lightweight and Efficient

●​ Uses basic Python modules, making it fast and reliable.


●​ No heavy NLP or ML libraries required.

10
11

Source Code.
#!/usr/bin/env python3​
"""​
Entertainment Chatbot - "EntertainMe"​
A lightweight terminal chatbot focused on jokes, movie/music suggestions,​
Mini-games, trivia, and small talk for entertainment purposes.​

Usage:​
python3 [Link]​
"""​
import random​
import sys​
import textwrap​

BOT_NAME = "EntertainMe"​

JOKES = [​
"Why did the scarecrow win an award? Because he was outstanding in his
field!",​
"I told my computer I needed a break, and now it won't stop sending me
KitKat ads.",​
"Why don't scientists trust atoms? Because they make up everything!",​
"I asked the librarian if the library had books on paranoia. She whispered,
'They're right behind you.'"​
]​

MOVIES = {​
"action": ["Mad Max: Fury Road", "John Wick", "The Dark Knight",
"Inception"],​
"comedy": ["The Grand Budapest Hotel", "Superbad", "Groundhog Day", "Hot
Fuzz"],​
"drama": ["The Shawshank Redemption", "Parasite", "Moonlight", "The
Godfather"],​
"sci-fi": ["Blade Runner 2049", "Arrival", "Interstellar", "The Matrix"],​
"romance": ["Pride & Prejudice", "La La Land", "Before Sunrise", "The
Notebook"]​
}​

SONGS = {​
"pop": ["Blinding Lights - The Weeknd", "Levitating - Dua Lipa", "Shake It
Off - Taylor Swift"],​
"rock": ["Bohemian Rhapsody - Queen", "Smells Like Teen Spirit - Nirvana",

11
12

"Hotel California - Eagles"],​


"electronic": ["Strobe - deadmau5", "Opus - Eric Prydz", "Ghosts 'n' Stuff -
deadmau5"],​
"chill": ["Weightless - Marconi Union", "Holocene - Bon Iver", "Sunset Lover
- Petit Biscuit"]​
}​

TRIVIA_QUESTIONS = [​
("What planet is known as the Red Planet?", "mars"),​
("Who wrote the play 'Romeo and Juliet'?", "william shakespeare"),​
("What is the largest mammal in the world?", "blue whale"),​
("In computing, what does 'CPU' stand for?", "central processing unit")​
]​

FUN_FACTS = [​
"Honey never spoils -- archaeologists have found edible honey in ancient
Egyptian tombs.",​
"A single strand of spaghetti is called a 'spaghetto'.",​
"There are more possible iterations of a game of chess than atoms in the
known universe (it's a lot!).",​
"Octopuses have three hearts."​
]​

def wrap(text):​
return "\n".join([Link](text, width=78))​

def greet():​
print(f"\nHi! I'm {BOT_NAME} -- your entertainment companion. What would you
like to do today?\n")​

def menu():​
print("Choose an option:")​
print(" 1) Tell me a joke")​
print(" 2) Movie recommendation")​
print(" 3) Music suggestion")​
print(" 4) Trivia quiz")​
print(" 5) Fun fact")​
print(" 6) Play Rock-Paper-Scissors")​
print(" 7) Small talk")​
print(" 0) Exit")​

def tell_joke():​
print("\n" + [Link](JOKES) + "\n")​

def recommend_movie():​

12
13

print("\nWhich genre are you in the mood for?


(action/comedy/drama/sci-fi/romance)")​
genre = input("Genre> ").strip().lower()​
choices = [Link](genre)​
if choices:​
print("\nTry watching: " + [Link](choices) + "\n")​
else:​
all_movies = sum([Link](), [])​
print("\nI don't know that genre -- how about: " +
[Link](all_movies) + "\n")​

def suggest_music():​
print("\nWhich vibe? (pop/rock/electronic/chill)")​
vibe = input("Vibe> ").strip().lower()​
choices = [Link](vibe)​
if choices:​
print("\nYou might like: " + [Link](choices) + "\n")​
else:​
all_songs = sum([Link](), [])​
print("\nNot sure about that vibe -- try: " + [Link](all_songs) +
"\n")​

def trivia_quiz():​
q, a = [Link](TRIVIA_QUESTIONS)​
print("\nTrivia: " + q)​
ans = input("Your answer> ").strip().lower()​
if ans == a or a in ans:​
print("Correct! Well done.\n")​
else:​
print(f"Nice try -- the answer is: {[Link]()}.\n")​

def fun_fact():​
print("\n" + [Link](FUN_FACTS) + "\n")​

def rps():​
choices = ["rock", "paper", "scissors"]​
user = input("\nChoose rock, paper, or scissors> ").strip().lower()​
if user not in choices:​
print("That's not a valid move.\n")​
return​
bot = [Link](choices)​
print(f"I chose {bot}.")​
if user == bot:​
print("It's a tie!\n")​
elif (user == "rock" and bot == "scissors") or (user == "paper" and bot ==

13
14

"rock") or (user == "scissors" and bot == "paper"):​


print("You win! Nicely played.\n")​

😎
else:​
print("I win this round. \n")​

def small_talk():​
replies = [​
"I'm here to keep you entertained -- want a joke or a trivia quiz?",​
"I can recommend movies or music -- tell me a mood!",​
"Feeling bored? Let's play a quick game.",​
"What's something you like? I can try to match it!"​
]​
print("\n" + [Link](replies) + "\n")​

def unknown():​
print("\nI didn't quite get that -- please choose a number from the
menu.\n")​

def main():​
greet()​
while True:​
menu()​
choice = input("Choice> ").strip()​
if choice == "1":​
tell_joke()​
elif choice == "2":​
recommend_movie()​
elif choice == "3":​
suggest_music()​
elif choice == "4":​
trivia_quiz()​
elif choice == "5":​
fun_fact()​
elif choice == "6":​
rps()​
elif choice == "7":​
small_talk()​
elif choice == "0":​
print(f"\nThanks for hanging out! Bye from {BOT_NAME}.\n")​
break​
else:​
unknown()​

if __name__ == '__main__':​
try:​

14
15

main()​
except (KeyboardInterrupt, EOFError):​
print(f"\n\nGoodbye from {BOT_NAME} -- come back soon!\n")

15
16

Output.

16
17

Limitations.
1.​ Rule-Based System:​
The chatbot works only on predefined keywords and cannot understand complex natural
language or sentence structures.
2.​ Limited Content Library:​
Jokes, riddles, and fun facts are restricted to the manually added lists, so content variety
depends entirely on what is stored in the program.
3.​ No Context Awareness:​
The chatbot cannot remember previous messages or maintain conversation flow beyond a
single query.
4.​ No Emotion Detection:​
It cannot recognize the user’s mood or tone (e.g., boredom, excitement, sadness) and cannot
adapt responses accordingly.
5.​ No Error/Spell Handling:​
Misspellings, abbreviations, or slang words are not recognized unless explicitly coded, leading
to reduced accuracy.
6.​ No Learning Ability:​
The chatbot cannot learn from user interactions since it does not use machine learning or NLP
technologies.
7.​ Text-Only Interaction:​
The bot only works in a console window and does not support voice input/output or a graphical
UI.
8.​ No Internet Connectivity:​
The chatbot cannot fetch new jokes or real-time information from the internet; content must be
updated manually.
9.​ Single-Intent Understanding:​
If a user asks for multiple things at once (e.g., a joke and a fun fact), the bot can respond to
only one intent at a time.
10.​Limited User Personalization:​
The chatbot cannot store or recognize user preferences (e.g., favorite type of jokes), making
interactions non-personalized.​

17
18

Conclusion.
The Entertainment Chatbot developed in this project successfully demonstrates how Python can be
used to create an interactive, engaging, and user-friendly conversational system. By using simple
keyword-based intent recognition, the chatbot is able to entertain users with jokes, riddles, fun facts,
and casual conversation. Through this project, I gained practical experience in text processing,
conditional logic, modular programming, and handling real-time user interaction.

The project highlights the potential of chatbots as entertaining digital companions and showcases how
even a simple rule-based system can provide enjoyable and meaningful engagement to users.
Although the chatbot is limited in its understanding and does not use advanced AI or machine
learning, it effectively fulfills its purpose as a fun and lightweight entertainment tool.

Overall, this project strengthened my understanding of Python programming and introduced me to the
foundational concepts of conversational interfaces. It also demonstrated how chatbots are widely used
in real-world entertainment platforms, games, social media, and digital assistants. With further
enhancements—such as NLP integration, GUI development, and content expansion—this
entertainment chatbot could evolve into a more intelligent and dynamic virtual companion.

18

You might also like