0% found this document useful (0 votes)
74 views3 pages

College Management

This Python program creates a college management system using MySQL. It defines functions for student, teacher, and admin operations including viewing and managing courses, students, grades, and user accounts. The main function displays a menu to call the respective operation functions for students, teachers, or admins. It connects to a MySQL database called college that contains tables for courses, students, and users.

Uploaded by

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

College Management

This Python program creates a college management system using MySQL. It defines functions for student, teacher, and admin operations including viewing and managing courses, students, grades, and user accounts. The main function displays a menu to call the respective operation functions for students, teachers, or admins. It connects to a MySQL database called college that contains tables for courses, students, and users.

Uploaded by

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

# PROGRAM FOR COLLEGE MANAGEMENT SYSTEM USING PYTHON-MYSQL

#create a database named as college and create table in collge databse


"""table name-- course table with field name=> name(char),code(varchar) and
>>students table with field name=>
name(char),roll_no(int),course(char),semester(varchar)
>>users table with field name=> username(char,password(varchar,privilege(char)"""

import mysql.connector as sql

# Connect to MySQL database


db = sql.connect(host="localhost", user="root", password="jk@2319",
database="college")

# Create cursor object


cursor = db.cursor()

# Function for student operations


def student_operations():
print("Student Operations")
while True:
print("1. View Courses")
print("2. Enroll in a Course")
print("3. View Grades")
print("4. Back to Main Menu")
choice = input("Enter your choice: ")

if choice == "1":
# View courses logic
cursor.execute("SELECT * FROM courses")
courses = cursor.fetchall()
for course in courses:
print(course)
elif choice == "2":
# Enroll in a course logic
course_id = input("Enter the course ID: ")
student_id = input("Enter your student ID: ")
# Your code to enroll the student in the course
elif choice == "3":
# View grades logic
student_id = input("Enter your student ID: ")
# Your code to fetch and display the student's grades
elif choice == "4":
break
else:
print("Invalid choice. Please try again.")

# Function for teacher operations


def teacher_operations():
print("Teacher Operations")
while True:
print("1. View Courses")
print("2. Add a Course")
print("3. Update Grades")
print("4. Back to Main Menu")
choice = input("Enter your choice: ")

if choice == "1":
# View courses logic
cursor.execute("SELECT * FROM courses")
courses = cursor.fetchall()
for course in courses:
print(course)
elif choice == "2":
# Add a course logic
course_id = input("Enter the course ID: ")
course_name = input("Enter the course name: ")
# Your code to add the course to the database
elif choice == "3":
# Update grades logic
student_id = input("Enter the student ID: ")
course_id = input("Enter the course ID: ")
new_grade = input("Enter the new grade: ")
# Your code to update the student's grade in the database
elif choice == "4":
break
else:
print("Invalid choice. Please try again.")

# Function for admin operations


def admin_operations():
print("Admin Operations")
while True:
print("1. Add Student")
print("2. Add Teacher")
print("3.Remove student ID")
print("4.Remove teacher ID")
print("5. Back to Main Menu")
choice = input("Enter your choice: ")

if choice == "1":
# Add student logic
student_id = input("Enter the student ID: ")
student_name = input("Enter the student name: ")
# Your code to add the student to the database
elif choice == "2":
# Add teacher logic
teacher_id = input("Enter the teacher ID: ")
teacher_name = input("Enter the teacher name: ")
# Your code to add the teacher to the database
elif choice =="3":
print("Delete Existing Student Account")
username = input(str("Student username : "))
query_vals = (username,"student")
command_handler.execute("DELETE FROM users WHERE username = %s AND
privilege = %s ",query_vals)
db.commit()
if command_handler.rowcount < 1:
print("User not found")
else:
print(username + " has been deleted")
elif choice=="4":
print("")
print("Delete Existing Teacher Account")
username = input(str("Teacher username : "))
query_vals = (username,"teacher")
command_handler.execute("DELETE FROM users WHERE username = %s AND
privilege = %s ",query_vals)
db.commit()
if command_handler.rowcount < 1:
print("User not found")
else:
print(username + " has been deleted")
elif choice == "5":
break
else:
print("Invalid choice. Please try again.")

# Main function
def main():
while True:
print("1. Student")
print("2. Teacher")
print("3. Admin")
print("4. Exit")
choice = input("Enter your choice: ")

if choice == "1":
student_operations()
elif choice == "2":
teacher_operations()
elif choice == "3":
admin_operations()
elif choice == "4":
break
else:
print("Invalid choice. Please try again.")

# Close database connection


db.close()

# Run the program


if __name__ == "__main__":
main()

You might also like