# 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 [Link] as sql
# Connect to MySQL database
db = [Link](host="localhost", user="root", password="jk@2319",
database="college")
# Create cursor object
cursor = [Link]()
# 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
[Link]("SELECT * FROM courses")
courses = [Link]()
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
[Link]("SELECT * FROM courses")
courses = [Link]()
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("[Link] student ID")
print("[Link] 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)
[Link]()
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)
[Link]()
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
[Link]()
# Run the program
if __name__ == "__main__":
main()