Here's a simplified Python version of the C code, focusing on the main functionalities while
avoiding complexities:
python
Copy code
class Student:
def __init__(self, student_id, name, password, credits, noc):
self.student_id = student_id
[Link] = name
[Link] = password
[Link] = credits # Total credits
[Link] = noc # Number of courses
# List to store student data
students = [
Student(1, 'john', '1234', 12, 3),
Student(2, 'jane', '5678', 15, 4),
]
uid = None # Will store the current logged-in user ID
def update_student(name, credits):
global students
for student in students:
if [Link] == name:
[Link] += credits
[Link] += 1
print(f"Updated {[Link]}: Credits = {[Link]}, Courses = {[Link]}")
def check_password(username, pwd):
global students, uid
for student in students:
if [Link] == username and [Link] == pwd:
uid = [Link] # Store logged in user's name
return True
return False
def change_password(current_password):
global students, uid
for student in students:
if [Link] == uid and [Link] == current_password:
new_password = input("Enter New Password: ")
[Link] = new_password
print(f"Password updated for {uid}")
return
print("Current password is incorrect!")
def login_menu():
while True:
print("\n1. Change Password")
print("2. Add Course")
print("3. Drop Course")
print("4. View Courses")
print("5. Logout")
choice = input("Choose an option: ")
if choice == '1':
current_pwd = input("Enter Current Password: ")
change_password(current_pwd)
elif choice == '2':
add_course()
elif choice == '3':
drop_course()
elif choice == '4':
view_courses()
elif choice == '5':
print("Logged out!")
break
def add_course():
# Add course functionality
print("Course added!")
def drop_course():
# Drop course functionality
print("Course dropped!")
def view_courses():
# View course functionality
print("Viewing courses!")
# Main login function
def main():
global uid
username = input("UserID: ")
password = input("Password: ")
if check_password(username, password):
print("Login successful!")
login_menu()
else:
print("Wrong username or password!")
if __name__ == '__main__':
main()
Explanation:
Student class: Stores student data (student_id, name, password, credits, and number of
courses).
Global students list: Acts like the file in the C version, storing the student information.
update_student(): Updates a student's credits and number of courses.
check_password(): Checks if the username and password are correct.
change_password(): Allows the logged-in user to change their password.
login_menu(): Displays the menu for logged-in users and allows them to perform
different actions.
This Python version mimics the core logic of the original C program but is easier to read and
understand with Python syntax.