加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python选课系统demo的小练习

发布时间:2020-12-20 10:48:15 所属栏目:Python 来源:网络整理
导读:# 简化选课系统代码:先登陆,然后判断身份并实例化,根据身份对应的类,让用户选择 class Manager: operate_dict = [ ( ‘ 创造学生账号 ‘ , " creat_student " ),( ‘ 查看学生信息 ‘ , " check_student " ) ] def __init__ (self,name): self.name = name d
#简化选课系统代码:先登陆,然后判断身份并实例化,根据身份对应的类,让用户选择
class Manager:
    operate_dict=[
        (创造学生账号,"creat_student"),(查看学生信息,"check_student")
                 ]
    def __init__(self,name):
        self.name=name
    def creat_student(self):
        print(创建学生账号)
    def check_student(self):
        print(查看学生信息)

class Student:
    def __init__(self,name):
        self.name = name
    def check(cls):
        print(查看课程)
    def login(cls):
        print(登录)

class Teacher:
    def __init__(self,name):
        self.name = name
def login():
    username=input(user:)
    password=input(password:)
    with open(userinfo)as f:
        for line in f :
            user,pwd,ident=line.strip().split(|)
            if user==username and pwd==password:
                print(登陆成功)
                return username,ident
import sys
def main():
    usr,id=login()
    file=sys.modules[__main__]
    cls=getattr(file,id)
    obj=cls(usr)
    Operate_dict=cls.operate_dict
    print(Operate_dict)
    for num,item in enumerate(Operate_dict):
        print(num,item[0])
    choice=int(input("num>>>"))
    choice_item=Operate_dict[choice-1]
    getattr(obj.choice_item[1])()
main()

接下来进行重点部分的分析

第一次跟着写,分析也是云里雾里的.可能还会更新吧(?)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读