Python Chatbot SQL File
Python Chatbot SQL File
PRINCIPAL
Acknowledgement
It is with pleasure that I acknowledge my sincere
gratitude to our teacher, MS. ANJU SRIVASTAV who
taught and undertook the responsibility of teaching the
subject computer science. I have been greatly
benefited from her classes. I am especially indebted to
our principal MS.SUDHA SINGH who has always been a
source of encouragement and support and without
whose inspiration this project would not have been a
successful I would like to place record heartfelt thanks
to him. Finally, I would like to express my sincere
appreciation for all the other students for my batch
their friendship & the fine time that we all share
together.
Hardware
1. PC
2. Laptop
Software
1. My sql (version 9.2.0)
2. Python (version 3.13.3)
3. Pyhton Connector Module
Content
Introduction_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ *
Code_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ *
Database_ __ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ *
Output_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ *
Reference_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _*
Introduction
Project Title:
Interactive Student Data Collection Chatbot using Python and MySQL
Introduction:
With everything getting digital these days, even schools and colleges are moving towards
smarter ways of collecting student information. Instead of the usual boring forms, I thought
of creating something a bit more interactive and fun—a chatbot! This project is about
building a simple chatbot in Python that talks to students, asks them questions like name,
class, age, etc., and then stores all that info in a MySQL database.
The idea is to make data collection more friendly and less formal. The chatbot (I named it
PyBoi) acts like a cool assistant that guides the student step-by-step, makes sure they don’t
leave anything important blank, and even gives friendly messages when something's not
right. It also makes sure the same roll number doesn’t get added twice.
Objective:
The goal of this project is to build a chatbot that:
Validates input (like checking if the name has only letters or if age is between 5 and
32).
It’s especially useful for teachers or admins who want to collect student info quickly, without
using long forms or Google Sheets.
Technologies Used:
Database Table:
The main table I used is called Info, and it has these columns:
Name
Class
Section
DOB
Father’s Name
Mother’s Name
Number of Siblings
Mobile Number
Country
State
Features:
The chatbot chats with the student like a person, asking one question at a time.
It doesn’t crash if someone enters something wrong—it shows a message and asks
again.
If someone’s age is too young or too old (not a student), it tells them politely and
skips.
It also gives some fun responses (like guessing nearby roll numbers or praising good
percentages).
Conclusion:
In the end, this chatbot makes student data collection smoother, faster, and a bit more
enjoyable. Instead of typing everything in a form, students just answer the bot. I learned a
lot about input validation, database connection, and handling errors while working on this.
In the future, I might try turning it into a web app or adding a simple GUI to make it even
better!
SOURCE CODE
import mysql.connector
import random
import re
# Connect to MySQL
conn = mysql.connector.connect(
host="localhost",
user="root",
password="Test",
database="ProjectX"
)
cursor = conn.cursor()
print("Hey! PyBoi here — Naman Vaths’ chatbot! I’ll ask you some stuff, and
please don’t leave blanks, okay?")
def is_empty_or_space(s):
return s.strip() == ""
# FATHER'S NAME
while True:
father = input("What’s your Father’s name? ").strip()
if is_empty_or_space(father):
print("Okay if you want to keep it private.")
father = ""
break
elif not father.replace(" ", "").isalpha():
print("Please enter only letters and spaces for your Father's name.")
else:
print(f"Your dad {father} sounds great!")
break
# MOTHER'S NAME
while True:
mother = input("What’s your Mother’s name? ").strip()
if is_empty_or_space(mother):
print("No worries if you want to keep it private.")
mother = ""
break
elif not mother.replace(" ", "").isalpha():
print("Please enter only letters and spaces for your Mother's name.")
else:
print(f"Your mom {mother} must be awesome!")
break
# NUMBER OF SIBLINGS
while True:
siblings = input("How many siblings do you have? ").strip()
if is_empty_or_space(siblings):
print("No problem if you want to skip this one.")
siblings = ""
break
elif siblings.isdigit():
print(f"{siblings} siblings! Sounds like a lively family!")
break
else:
print("Please enter a number for siblings.")
# MOBILE NUMBER
while True:
mobile = input("Your Mobile Number? (digits only) ").strip()
if is_empty_or_space(mobile):
print("Okay, no worries if you want to keep it private.")
mobile = ""
break
elif mobile.isdigit() and 7 <= len(mobile) <= 15:
print(f"Thanks! I'll remember your number ending with {mobile[-4:]}.")
break
else:
print("Mobile number should be digits only and 7-15 digits long.")
# COUNTRY
while True:
country = input("Which country do you live in? ").strip()
if is_empty_or_space(country):
print("No problem if you want to keep it private.")
country = ""
break
elif not country.replace(" ", "").isalpha():
print("Country names usually only have letters and spaces. Try again?")
else:
print(f"{country} sounds like a wonderful place!")
break
# STATE
while True:
state = input("Which state are you from? ").strip()
if is_empty_or_space(state):
print("It's cool if you want to skip this.")
state = ""
break
elif not state.replace(" ", "").isalpha():
print("Please enter only letters and spaces for your state.")
else:
print(f"{state} must have some great stories!")
break
# STREAM
while True:
stream = input("Which stream are you in? (Science/Commerce/Arts/Other)
").strip().capitalize()
if is_empty_or_space(stream):
print("No problem if you want to skip your stream.")
stream = ""
break
elif not stream.isalpha():
print("Stream names should be letters only. Try again!")
else:
print(f"{stream} is a fantastic stream!")
break
print("\nAwesome chatting with you! Thanks for sharing all this info with me :)")
cursor.execute(Sql, Value)
conn.commit()
MySQL DATABASES
1) SETTING TARGETED DATABASE