pythonによる簡単な学習者情報管理システムの作成


具体的な考え方:
  • まず、1つの辞書で学習者の情報を格納する(「no」は学号が唯一であり、名前、年齢、クラス、成績の重複現象は現れないため)「no」学号で学習者の集団情報
  • を表す.
  • は、このシステムのすべての機能
  • をユーザに伝える.
  • は、各機能
  • をメソッド(関数)により記憶する.
  • は最後にメイン関数main()によってこれらの機能
  • を呼び出す.
    #             
    #          
    all_stu={"01":{"no":"01","name":"  ","age":23,"cla":"  ","achi":87}}
    
    def ser():
        print("===========================")
        print("---------        ----------")
        print("1:     ")
        print("2:    ")
        print("3:    ")
        print("4:    ")
        print("5:      ")
        print("6:          ")
        print("7:      ")
        print("8:    ")
        print("===========================")
    
    
    #     
    def add_mem():
        stu_no = input("     ")
        if stu_no not in all_stu:
    
            stu_name = input("     ")
            stu_age = int(input("     "))
            stu_cla = input("     ")
            stu_achi = int(input("     "))
            stu_sum = {"no":stu_no,"name":stu_name,"age":stu_age,"cla":stu_cla,"achi":stu_achi}
            all_stu[stu_no]=stu_sum
            print("    ")
        else:
            print("       ")
    
    #     
    def del_stu():
        while True:
            stu_no = input("           ")
            if stu_no in all_stu:
                del all_stu[stu_no]
                return
            else:
                print("      ")
    
    #     
    def mod_stu():
        while True:
            stu_no = input("            ")
            if stu_no in all_stu:
                new_name = input("       ")
                new_age = int(input("       "))
                new_cla = input("      ")
                new_achi = int(input("       "))
                stu_sum = {"no": stu_no, "name": new_name, "age": new_age, "cla": new_cla,"achi":new_achi}
                all_stu[stu_no] = stu_sum
                return
            else:
                print("      !")
    #     
    def que_stu():
        while True:
            stu_no = input("        ")
            if stu_no in all_stu:
                str_dick = all_stu[stu_no]
                print(str_dick)
                return
            else:
                print("      ")
    
    #              key    volue  (       )
    def show_stu():
        for inm in all_stu.values():
            print("="*33)
            print("  :%s***  :%s***  :%d***  :%s***  :%d " %(inm["no"],inm["name"],inm["age"],inm["cla"],inm["achi"]))
            print("==========       ==========")
    
    #    
    def aver_stu():
        l = len(all_stu)
        sum = 0
        for irm in all_stu.values():
            sm = irm["achi"]
            sum+=sm
        ss = sum/l
        print("    :%d" %ss)
    
    #    
    def pas_stu():
        l = len(all_stu)
        sum = 0
        for irm in all_stu.values():
            sm = irm["achi"]
            if sm>60 and sm<100:
                sum += 1
                ss=sum/l*100
                print("    :%d%%"%ss)
    
    #          
    def main():
        while True:
            ser()
            sel_fun=int(input("         :"))
            #      
            if sel_fun == 1:
                add_mem()
                print(all_stu)
                #     
            elif sel_fun == 2:
                del_stu()
                # print(all_stu)
                
            #     
            elif sel_fun == 3:
                mod_stu()
                # print(all_stu)
                
            #     
            elif sel_fun == 4:
                que_stu()
                
            #       
            elif sel_fun == 5:
                show_stu()
                
            #    
            elif sel_fun == 7:
                aver_stu()
                
            #    
            elif sel_fun ==8:
                pas_stu()
                
            #     
            elif sel_fun == 6:
                return
                
    
    main()