""" Project name : python-learning Description : A SIMPLE STUDENT MANAGEMENT SYSTEM Author : 黄宇辉 Version : 1.0 Website : https://yubuntu0109.github.io/ Created on 11/8/2019-6:47 PM """
# CREATE A LIST WHICH BE USED TO STORE ALL OF STUDENT INFORMATIONS student_infos = []
# OUTPUT THE MENU INFO INTO THE CONSOLE defprint_menu(): print("=" * 50) print("### A SIMPLE STUDENT MANAGEMENT SYSTEM v1.0 ###") print("1:ADD THE STUDENT INFORMATION") print("2:DELETE THE STUDENT INFORMATION") print("3:MODIFY THE STUDENT INFORMATION") print("4:DISPLAY ALL OF STUDENT INFORMATIONS") print("5:SAVE ALL OF STUDENT INFORMATIONS") print("0:EXIT") print("=" * 50)
# ADD A NEW STUDENT INFORMATION defadd_info(): new_name = input("PLEASE ENTER THE NEW STUDENT'S NAME: ") new_sex = input("PLEASE ENTER THE NEW STUDENT'S SEX: ") new_phone = input("PLEASE ENTER THE NEW STUDENT'S PHONE: ") new_info = {'name': new_name, 'sex': new_sex, 'phone': new_phone} student_infos.append(new_info)
# DELETE THE SPECIFIED STUDENT INFORMATION BY NO defdel_info(): del_number = int(input("PLEASE THE SPECIFIED STUDENT' NO: ")) - 1# index del student_infos[del_number]
# MODIFY THE SPECIFIED STUDENT INFORMATION BY NO defmodify_info(): student_id = int(input("PLEASE THE STUDENT NO: ")) new_student_name = input("PLEASE ENTER THE NEW NAME: ") new_student_sex = input("PLEASE ENTER THE NEW SEX: ") new_student_phone = input("PLEASE ENTER THE NEW PHONE: ") student_infos[student_id - 1]['name'] = new_student_name student_infos[student_id - 1]['sex'] = new_student_sex student_infos[student_id - 1]['phone'] = new_student_phone
# DISPLAY ALL OF STUDENT INFORMATIONS defshow_infos(): print("=" * 50) print("ALL OF STUDENT INFORMATION BE SHOWED AS FOLLOW") print("=" * 50) print("NO NAME SEX PHONE") i = 1 for temp in student_infos: print("%d %s %s %s" % (i, temp['name'], temp['sex'], temp['phone'])) i += 1
# SAVE ALL OF STUDENT INFORMATIONS defsave_data(): try: file = open("db.data", "w") file.write(str(student_infos)) file.close() except FileNotFoundError: print("CATCH THE EXCEPTION: THE SPECIFIED FILE NOT EXIST!") else: # so simple and so cool than Java print("SAVE ALL OF STUDENT INFORMATIONS SUCCESSFULLY")
# RECOVER ALL OF STUDENT INFORMATIONS defrecover_data(): global student_infos try: file = open("db.data", "wb+") # create new file if the specified file not exist content = file.read() print(content) # throw the SyntaxError possibly: unexpected EOF while parsing student_infos = eval(content) file.close() except (SyntaxError, FileNotFoundError) as exception_info: print("CATCH THE EXCEPTION: %s" % exception_info)
# MAIN FUNCTION defmain(): recover_data() # the specified file must store some datas before reading whileTrue: print_menu() key = input("PLEASE ENTER THE SPECIFIED NO OF MENU: ") if key == '1': add_info() elif key == '2': del_info() elif key == '3': modify_info() elif key == '4': show_infos() elif key == '5': save_data() elif key == '0': quit_confirm = input("ARE YOU SURE TO QUIT ?( Yes or No ): ") if quit_confirm == "Yes": break else: print("ERROR : PLEASE ENTER THE RIGHT COMMAND !")
CATCH THE EXCEPTION: unexpected EOF while parsing (<string>, line 0)
================================================== ### A SIMPLE STUDENT MANAGEMENT SYSTEM v1.0 ### 1:ADD THE STUDENT INFORMATION 2:DELETE THE STUDENT INFORMATION 3:MODIFY THE STUDENT INFORMATION 4:DISPLAY ALL OF STUDENT INFORMATIONS 5:SAVE ALL OF STUDENT INFORMATIONS 0:EXIT ================================================== PLEASE ENTER THE SPECIFIED NO OF MENU: 1 PLEASE ENTER THE NEW STUDENT'S NAME: 黄宇辉 PLEASE ENTER THE NEW STUDENT'S SEX: 男 PLEASE ENTER THE NEW STUDENT'S PHONE: 00000000000
================================================== ### A SIMPLE STUDENT MANAGEMENT SYSTEM v1.0 ### 1:ADD THE STUDENT INFORMATION 2:DELETE THE STUDENT INFORMATION 3:MODIFY THE STUDENT INFORMATION 4:DISPLAY ALL OF STUDENT INFORMATIONS 5:SAVE ALL OF STUDENT INFORMATIONS 0:EXIT ================================================== PLEASE ENTER THE SPECIFIED NO OF MENU: 4
================================================== ALL OF STUDENT INFORMATION BE SHOWED AS FOLLOW ================================================== NO NAME SEX PHONE 1 黄宇辉 男 00000000000
================================================== ### A SIMPLE STUDENT MANAGEMENT SYSTEM v1.0 ### 1:ADD THE STUDENT INFORMATION 2:DELETE THE STUDENT INFORMATION 3:MODIFY THE STUDENT INFORMATION 4:DISPLAY ALL OF STUDENT INFORMATIONS 5:SAVE ALL OF STUDENT INFORMATIONS 0:EXIT ================================================== PLEASE ENTER THE SPECIFIED NO OF MENU: 5 SAVE ALL OF STUDENT INFORMATIONS SUCCESSFULLY