0% found this document useful (0 votes)
4 views18 pages

Python Chatbot SQL File

The document certifies that Naman Vaths, a student of Ryan International School, completed a project on a data-collecting chatbot under supervision. The chatbot, named PyBoi, utilizes Python and MySQL to interactively gather student information while ensuring data validation and preventing duplicates. The project aims to modernize data collection in educational settings, making it more engaging and efficient.

Uploaded by

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

Python Chatbot SQL File

The document certifies that Naman Vaths, a student of Ryan International School, completed a project on a data-collecting chatbot under supervision. The chatbot, named PyBoi, utilizes Python and MySQL to interactively gather student information while ensuring data validation and preventing duplicates. The project aims to modernize data collection in educational settings, making it more engaging and efficient.

Uploaded by

Eternity Gamer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Certificate

This is to certify that NAMAN VATHS student of


class XII C of RYAN INTERNATIONAL SCHOOL,
GREATER NOIDA has done her project on DATA
COLLECTING CHATBOT under my supervision. She
has taken her interest and has shown at most
sincerity in completion of this project. I certified
this project upto my expectation and as per
guidelines issued by CBSE, NEW DELHI

INTERNAL EXAMINER EXTERNAL EXAMINER

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.

NAME : SUBHASMITA PANIGRAHI


TEACHER: ANJU SRIVASTAV
CLASS: XII-A
SIGN :
Hardware And Software Required

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:

 Collects student information through conversation.

 Validates input (like checking if the name has only letters or if age is between 5 and
32).

 Stores everything in a MySQL database safely.

 Avoids duplicates by checking if a roll number already exists.

It’s especially useful for teachers or admins who want to collect student info quickly, without
using long forms or Google Sheets.

Technologies Used:

 Python – for coding the chatbot and handling the logic.

 MySQL – to store all the data in a proper, organized way.

 mysql-connector-python – to connect Python and MySQL.

Database Table:
The main table I used is called Info, and it has these columns:

 RollNo (Primary Key)

 Name

 Class
 Section

 PercentageClassX (only asked if class is more than 10)

 Age (only accepts 5 to 32)

 DOB

 Father’s Name

 Mother’s Name

 Number of Siblings

 Mobile Number

 Country

 State

 Stream (Science, Commerce, Arts, etc.)

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 checks if the Roll No is already taken and avoids saving it again.

 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() == ""

# NAME - only letters (no numbers or special chars)


while True:
name = input("First up, what’s your name? ").strip()
if is_empty_or_space(name):
print("Ah, it's cool if you want to skip your name, but I’d love to know it!")
elif not name.replace(" ", "").isalpha():
print("Hmm, your name should have only letters and spaces. Try again,
please!")
else:
print(f"Hey {name}, nice to meet you!")
break

# CLASS - must be integer (like 1, 10, 12)


while True:
_class = input("Which class are you studying in? ").strip()
if is_empty_or_space(_class):
print("You don’t have to tell me your class if you don’t want to.")
break
elif _class.isdigit():
_class = int(_class)
print(f"Cool, class {_class} is full of energy, I bet!")
break
else:
print("Please enter your class as a number, like 10 or 12.")

# ROLL NO - must be unique, positive integer


while True:
rollno_input = input("What’s your Roll No? (Can’t leave blank or zero)
").strip()
if is_empty_or_space(rollno_input):
print("Roll No is super important, so please don’t leave it empty.")
continue
elif not rollno_input.isdigit():
print("Roll No should be a positive number. Give it another go!")
continue
rollno = int(rollno_input)
if rollno <= 0:
print("Roll No can’t be zero or negative. Try again!")
continue

# Check if roll no already exists


cursor.execute("SELECT RollNo FROM Info WHERE RollNo = %s", (rollno,))
if cursor.fetchone():
print(f"Roll No {rollno} already exists. Please enter a different one.")
continue

rollno_minus = rollno - random.randint(1, 5)


rollno_plus = rollno + random.randint(1, 5)
print(f"Nice! Usually, folks named {name} have roll no {rollno_minus} or
{rollno_plus} too.")
break

# SECTION - typically one letter (A, B, C)


while True:
section = input("Which section are you in? (A, B, C, etc.) ").strip().upper()
if is_empty_or_space(section):
print("No worries if you want to skip the section.")
section = ""
break
elif len(section) == 1 and section.isalpha():
print(f"Section {section}, nice choice!")
break
else:
print("Section should be a single letter. Try again!")

# PERCENTAGE Class X - only ask if class > 10


perc = ""
if isinstance(_class, int) and _class > 10:
while True:
perc = input("Your Class X percentage? (0 to 100) ").strip()
if is_empty_or_space(perc):
print("Okay, no problem if you don’t want to share your percentage.")
perc = ""
break
try:
perc_val = float(perc)
if 0 <= perc_val <= 100:
print(f"Sweet! {perc_val}% is pretty neat.")
break
else:
print("Percentage must be between 0 and 100. Try again!")
except ValueError:
print("That doesn’t look like a number. Please enter a valid
percentage.")
# AGE - integer between 5 and 32
while True:
age_in = input("How old are you? ").strip()
if is_empty_or_space(age_in):
print("Age is personal — no problem if you don’t want to say.")
break
if age_in.isdigit():
age = int(age_in)
if 5 <= age <= 32:
print(f"{age} years young! Nice!")
break
elif age < 5:
print("Oh, this chatbot is designed for someone older.")
elif age > 32:
print("Oh, this chatbot is designed for someone younger.")
else:
print("Age should be a number, please.")

# DOB - SQL date format YYYY-MM-DD


while True:
dob = input("Your Date of Birth? Please use YYYY-MM-DD format: ").strip()
if is_empty_or_space(dob):
print("No worries if you want to keep your DOB private.")
dob = ""
break
if re.match(r"^\d{4}-\d{2}-\d{2}$", dob):
print(f"Got it, your DOB is {dob}.")
break
else:
print("Please type your DOB exactly like YYYY-MM-DD, e.g., 2005-04-15.")

# 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 :)")

# Final INSERT query


Sql = "INSERT INTO Info (RollNo, Name, Class, Section, PercentageClassX, Age,
DOB, FatherName, MotherName, SiblingNo, MobileNo, Country, State, Stream)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
Value = (rollno, name, _class, section, perc, age_in, dob, father, mother,
siblings, mobile, country, state, stream)

cursor.execute(Sql, Value)
conn.commit()
MySQL DATABASES
1) SETTING TARGETED DATABASE

Our targeted databased we


used in
conn
=mysql.connector.connect
(
host="localhost",
user="root",
password="Test",
database="ProjectX")

2) USING THE CORRECT TABLE

The Table we choose to insert the


information we collected, Its used
here:
Sql = "INSERT INTO Info
(RollNo, Name, Class, Section,
PercentageClassX, Age, DOB,
FatherName, MotherName,
SiblingNo, MobileNo, Country,
State, Stream) VALUES (%s,
%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
Value = (rollno, name, _class, section, perc, age_in, dob, father, mother,
siblings, mobile, country, state, stream)

3) THE FIELDS IN THE TABLE


4) EMPTY TABLE TO COLLECT INFORMATION AND STORE IT

5) CHECKING YOUR USER AND HOST


OUTPUTS
1) Taking inputs
2) Stored Data

3) Primary Key Safety


4) Correct Data type Check and null option
REFERENCES:
In order to work on this project titled – ‘DATA COLLECTING CHATBOT’
the following books and websites are referred by me during the
various phases of development of the project.

1) Phyton Tutorials  https://www.w3schools.com/python/


2) Computer science with PYTHON (Sumita Arora)
3) Guide  https://pynative.com/python-mysql-database-
connection/
Other than the above-mentioned books, the suggestions
and supervision of my teacher and my class experience
also helped me to develop this software project.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy