CLASS 12 COMPUTER PROJECT
CLASS 12 COMPUTER PROJECT
HIGH SCHOOL
NAME-SOHAN DASGUPTA
CLASS-XII
ROLL NO-12678158
Acknowledgement
It is with pleasure that I acknowledge my
sincere gratitude to our teacher, MRS. PRIYANKA
GHOSH who taught me and had undertaken
the responsibility of teaching the subject
computer science. I have been greatly benefited
from his classes.
I also acknowledge with a deep sense of reverence,
my gratitude towards my parents, other faculty
Members of the school and friends for their valuable
Suggestions given to me in completion of the project
SIGNATURE
CERTIFICATE
import mysql.connector
# Connect to the MySQL database
def connect_to_db():
try:
conn = mysql.connector.connect(
host="localhost", #
Replace with your host
user="root", #
Replace with your username
passwd="manager", # Replace
with your password
database="timetable_db" #
Replace with your database name
)
return conn
except mysql.connector.Error as e:
print(f"Error connecting to
database: {e}")
return None
# Create timetable table
def create_table():
conn = connect_to_db()
if conn:
cursor = conn.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS
timetable (
id INT AUTO_INCREMENT PRIMARY
KEY,
day VARCHAR(10),
subject VARCHAR(50),
start_time TIME,
end_time TIME,
teacher VARCHAR(50)
)
""")
conn.commit()
conn.close()
print("Timetable table created
successfully.")
# Add an entry to the timetable
def add_entry(day, subject, start_time,
end_time, teacher):
conn = connect_to_db()
if conn:
cursor = conn.cursor()
query = "INSERT INTO timetable
(day, subject, start_time, end_time,
teacher) VALUES (%s, %s, %s, %s, %s)"
cursor.execute(query, (day,
subject, start_time, end_time, teacher))
conn.commit()
conn.close()
print("Entry added successfully.")
# View all timetable entries
def view_entries():
conn = connect_to_db()
if conn:
cursor = conn.cursor()
cursor.execute("SELECT * FROM
timetable")
rows = cursor.fetchall()
conn.close()
print("Timetable Entries:")
for row in rows:
print(row)
# Update an entry in the timetable
def update_entry(entry_id, day, subject,
start_time, end_time, teacher):
conn = connect_to_db()
if conn:
cursor = conn.cursor()
query = """
UPDATE timetable
SET day=%s, subject=%s,
start_time=%s, end_time=%s, teacher=%s
WHERE id=%s
"""
cursor.execute(query, (day,
subject, start_time, end_time, teacher,
entry_id))
conn.commit()
conn.close()
print("Entry updated
successfully.")
# Delete an entry from the timetable
def delete_entry(entry_id):
conn = connect_to_db()
if conn:
cursor = conn.cursor()
query = "DELETE FROM timetable
WHERE id=%s"
cursor.execute(query, (entry_id,))
conn.commit()
conn.close()
print("Entry deleted
successfully.")
# Main menu
def main():
create_table()
while True:
print("\nTimetable Management
System")
print("1. Add Entry")
print("2. View Entries")
print("3. Update Entry")
print("4. Delete Entry")
print("5. Exit")
choice = input("Enter your choice:
")
if choice == "1":
day = input("Enter day: ")
subject = input("Enter
subject: ")
start_time = input("Enter
start time (HH:MM:SS): ")
end_time = input("Enter end
time (HH:MM:SS): ")
teacher = input("Enter teacher
name: ")
add_entry(day, subject,
start_time, end_time, teacher)
elif choice == "2":
view_entries()
elif choice == "3":
entry_id = int(input("Enter
entry ID to update: "))
day = input("Enter new day: ")
subject = input("Enter new
subject: ")
start_time = input("Enter new
start time (HH:MM:SS): ")
end_time = input("Enter new
end time (HH:MM:SS): ")
teacher = input("Enter new
teacher name: ")
update_entry(entry_id, day,
subject, start_time, end_time, teacher)
elif choice == "4":
entry_id = int(input("Enter
entry ID to delete: "))
delete_entry(entry_id)
elif choice == "5":
print("Exiting.==")
break
else:
print("Invalid choice. Please
try again.")
if __name__ == "__main__":
main()
OUTPUT
ADD ENTRY:
VIEW ENTRIES:
UPDATE ENTRY:
DELETE ENTRY:
EXIT:
REFERENCES
• Wikipedia
https://www.wikipedia.org/
• Python
https://www.python.org/
• MySQL
https://www.mysql.com/
• Class 11th & 12 th Computer Science Books
(SUMITA ARORA)