Student Information Management System

students_info={
    '3130660001':{
        'name':'Ayi',
        'passwd':'000000',
        'gender': 1, #1: male, 2: female
        'class':1,
        'born':1994/5
    }
}
admin_info={
    'root':'passwd'
}

#admin module
def admin():
    admin_menu="""
          1. Administrator login,
          2. Change the administrator password,
          3. Add the student's information,
          4. Delete the student's information,
          5. Modify the student's information,
          6. Check the student's information (according to the student number),
          7. View the information of all students,
          8. Exit the system (exit(0)),
    """
    print("Welcome to the administrator login system interface!".center(40,'*'))
    print(admin_menu)
    choice=int(input('Please enter your choice:'))
    if choice==1:
        trycount = 0
        while trycount < 3:
            trycount += 1
            inuser = input("Username: ").strip()
            if inuser in admin_info: # Determine whether the user exists?
                inpasswd = input('password:')
                passwd = admin_info[inuser]['passwd'] # Find out the password of the inuser user stored in the system
                if inpasswd == passwd: # Determine if the password is correct?
                    print('%s login successfully!' % (inuser))
                    break
                else:
                    print('Incorrect password for user %s!' % (inuser))
            else:
                print('Username %s does not exist' % (inuser))
        else:
            print('More than 3 attempts!')
    elif choice==2:
        print('You choose to change the password this function!')
        while True:
            newpasswd=input('Please enter a new password:')
            if not newpasswd:
                print('Password cannot be empty, please re-enter')
            else:
                break
            againpasswd=input('Please enter the password again:').strip()
            if  againpasswd==newpasswd:
                admin_info['inuser']=newpasswd
    elif choice ==3:
        print('You choose to add student information to this function!')
        inname=input("Please enter the name of the student you want to add: ").strip()
        student_ID=input('Please enter the student ID (the student ID cannot be repeated):')
        gender = input("Gender (1-male, 2-female): ")
        age = int(input("*年龄:"))
        if student_ID in students: # Determine whether the student ID already exists?
            print('User %s already exists!' % (inname))
        else:
            student_info = {} #Define a dictionary to store information about a single student
            student_info['id'] = student_ID
            student_info['name'] = inname
            student_info['gender'] = gender
            student_info['age'] = age

            students.append(student_info)
            print('Student %s added successfully' % (inname))


    elif choice ==4:
        print('You chose to delete the student function')
        delId=input('Please enter the student ID to delete:')
        if delId not in students_info:
            print('Please enter the correct student number')
        else:
            print('Student information of student number %s: %s'%(delId,students_info))
            del students_info[delId]
            print('The student information has been deleted')




    elif choice ==5:
        while True:
            modId=input('Please enter the student ID of the student to be modified:').strip()
            if modId not in students_info:
                print('The student information does not exist')
            else:
                print('The information of student number %s is: %s'% (modId,students_info))
                print('Please enter the modified information:')
                while True:
                    modname=input('*Name:').strip()
                    if not modname:
                        print('Name cannot be empty')
                    else:
                        break
                while True:
                    modgender=input('Gender(1-male, 2-female):').strip()
                    if not modgender:
                        modgender=None
                    else:
                        modgender=modgender
                        break
                modclass=input('class:').strip()
                if not modclass:
                    modclass=None
                else:
                    modclass=modclass
                modborn=input('Birth year (year/month):').strip()
                if not modborn:
                    modborn=None
                else:
                    modborn=modborn
                modpasswd=input('*password:')
                if not modpasswd:
                    print('Password cannot be empty, please re-enter!')
                else:
                    modpasswd = modpasswd
                    break
            students_info[modId]={
                'name':modname,
                'gender':modgender,
                'class':modclass,
                'born':modborn,
                'passwd': modpasswd
            }
            print('Information modified successfully!')
            break


    elif choice ==6:
        while True:
            lookId=input('Please enter the student ID number: ').strip()
            if lookId not in students_info:
                print('No student information')
            else:
                print(students_info[lookId])
    elif choice ==7:
        print(students_info)
    elif choice ==8:
        exit(0)
    else:
        print('Error! Your selection is wrong, please enter the correct selection! Thank you!')
#Student operation module:
def students():
    student_menu = """
            1. Student login,
            2. Inquire about personal information,
            3. Modify personal information,
            4. Log out the user
    """
    print('01-Student login system interface'.center(40,'*'))
    while True:
       print(student_menu)
       choice2=int(input('Please enter your choice:'))
       if choice2==1:
         for j in range(3):

             student_name=input('Please enter the user name (student number):').strip()
             if student_name not in students_info:

                 print('The user does not exist! Please re-enter:')
             else:
                 student_passwd=input('Please enter the password:').strip()
                 if student_passwd==students_info[student_name]:
                     print('Login successful!')
                 else:
                     print('password error')
         else:
             print('Try more than 3 times, exit the system')
       elif choice2==2:
          print(students_info[student_name])
       elif choice2==3:
          cla=input('class:').strip()
          if not cla:
            cla = None
          else:
            cla =cla
          born=input('Birth year (year/month):')
          if not born:
            born=None
          else:
            born=born
          while True:
            passwd = input('password:').strip()
            if not passwd:
                print('Password cannot be empty')
            else:
                break
          m = input('<1: confirm modification 2; cancel>').strip()
          if m =='1':
              students_info[student_name]['class']=cla
              students_info[student_name]['born']=born
              students_info[student_name]['passwd']=passwd
              print('Information modified successfully!')
              break
          elif m =='2':
              break
          else:
              print('Invalid input')
       elif choice2 ==4:
          exit(0)
       else:
          print('Please enter the correct choice')

def main():
    menu='''
              1. Admin login
              2. Student login
    '''
    print('Student Information Management System'.center(40,'*'))
    print(menu)
    while True:
        choice1 = int(input('Please enter your choice:'))
        if choice1==1:
            admin()
        elif choice1==2:
            students()
        else:
            print('Please enter the correct choice!')
main()

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325762643&siteId=291194637
Recommended