亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Python選課系統(tǒng)開發(fā)程序

 更新時(shí)間:2016年09月02日 11:57:11   作者:Assassinの  
這篇文章主要為大家詳細(xì)介紹了Python選課系統(tǒng)開發(fā)程序,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文程序針對Python選課系統(tǒng)進(jìn)行開發(fā),供大家參考,具體內(nèi)容如下

角色:學(xué)校、學(xué)員、課程、講師
要求:
1. 創(chuàng)建北京、上海 2 所學(xué)校
2. 創(chuàng)建linux , python , go 3個(gè)課程 , linux\py 在北京開, go 在上海開
3. 課程包含,周期,價(jià)格,通過學(xué)校創(chuàng)建課程
4. 通過學(xué)校創(chuàng)建班級, 班級關(guān)聯(lián)課程、講師
5. 創(chuàng)建學(xué)員時(shí),選擇學(xué)校,關(guān)聯(lián)班級
5. 創(chuàng)建講師角色時(shí)要關(guān)聯(lián)學(xué)校,
6. 提供兩個(gè)角色接口
7. 學(xué)員視圖, 可以注冊, 交學(xué)費(fèi), 選擇班級,
8. 講師視圖, 講師可管理自己的班級, 上課時(shí)選擇班級, 查看班級學(xué)員列表 , 修改所管理的學(xué)員的成績
9. 管理視圖,創(chuàng)建講師, 創(chuàng)建班級,創(chuàng)建課程
10. 上面的操作產(chǎn)生的數(shù)據(jù)都通過pickle序列化保存到文件里 

程序: 

1、最最重要的readme: 

### 作者介紹:
* author:lzl
### 博客地址:
* http://www.cnblogs.com/lianzhilei/p/5813986.html

### 功能實(shí)現(xiàn)
    1. 創(chuàng)建北京、上海 2 所學(xué)校
    2. 創(chuàng)建linux , python , go 3個(gè)課程 , linux\py 在北京開, go 在上海開
    3. 課程包含,周期,價(jià)格,通過學(xué)校創(chuàng)建課程
    4. 通過學(xué)校創(chuàng)建班級, 班級關(guān)聯(lián)課程、講師
    5. 創(chuàng)建學(xué)員時(shí),選擇學(xué)校,關(guān)聯(lián)班級
    5. 創(chuàng)建講師角色時(shí)要關(guān)聯(lián)學(xué)校,
    6. 提供兩個(gè)角色接口
    6.1 學(xué)員視圖, 可以注冊, 交學(xué)費(fèi), 選擇班級,
    6.2 講師視圖, 講師可管理自己的班級, 上課時(shí)選擇班級, 查看班級學(xué)員列表 , 修改所管理的學(xué)員的成績
    6.3 管理視圖,創(chuàng)建講師, 創(chuàng)建班級,創(chuàng)建課程
    7. 上面的操作產(chǎn)生的數(shù)據(jù)都通過pickle序列化保存到文件里
    (所有功能均實(shí)現(xiàn))

###程序需知
    1. 當(dāng)前數(shù)據(jù)庫已建立好信息,可以直接進(jìn)行查看增加
        北京  課程:Python   講師:金角大王     班級:S14      學(xué)員:我要學(xué)python
              課程:Linux    講師:銀角大王     班級:L01      學(xué)員:我要學(xué)Linux
        上海  課程:Go       講師:天棚元帥     班級:G01      學(xué)員:我要學(xué)GO
    2. 也可以把database下的兩個(gè)數(shù)據(jù)庫文件刪除掉,數(shù)據(jù)清空,執(zhí)行程序,數(shù)據(jù)庫進(jìn)行初始化,初始化只生成北京、上海學(xué)校名
    3. 數(shù)據(jù)庫結(jié)構(gòu)main_dict 儲存主要的邏輯結(jié)構(gòu):
        {學(xué)校名:{課程名1:{"teacher":講師,"grade":班級},課程名2:{"teacher":講師2,"grade":班級2}},
        學(xué)校名:{課程名3:{"teacher":講師3,"grade":班級3},課程名4:{"teacher":講師4,"grade":班級4}}}
        存儲的數(shù)據(jù)類型都為實(shí)例對象
       數(shù)據(jù)庫結(jié)構(gòu)teacher_dict 存儲講師與班級的對應(yīng)關(guān)系,用于方便講師登錄系統(tǒng)認(rèn)證,結(jié)構(gòu)為
        {講師:{grade:班級}
        兩個(gè)數(shù)據(jù)庫文件均可擴(kuò)展
    4. 程序?qū)崿F(xiàn)了以下嚴(yán)格限制:
       ①一個(gè)學(xué)校里面不能出現(xiàn)同名的課程
       ②一個(gè)課程只能有一個(gè)講師
       ③講師被聘用后,不能再進(jìn)行聘用,一個(gè)講師也只能教一門課程(教python,就不能再教linux了)
       ④班級只能對應(yīng)一門課程,班級名只能出現(xiàn)一次,不能重復(fù)(python班級s14,linux的班級就不能再出現(xiàn)s14班級了)

###后期擴(kuò)展
     程序沒有定義學(xué)生類,后期可定義類,添加學(xué)生屬性(年齡,成績),對可學(xué)生成績信息進(jìn)行修改,把功能添加到教師中心,很顯然
     我沒時(shí)間了。。。。。
     程序按功能分出不同的模塊,可以更簡潔

2、程序目錄結(jié)構(gòu): 

3、數(shù)據(jù)庫: 

main_dict和teacher_dict兩個(gè)數(shù)據(jù)庫文件可不創(chuàng)建,運(yùn)行程序自動生成  

4、程序main.py 

#!/usr/bin/env python
# -*- coding:utf-8 -*-
#-Author-Lian 

import pickle,os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
#數(shù)據(jù)地址
__db_main = BASE_DIR + r"\database\main_dict"
__db_teacher = BASE_DIR + r"\database\teacher_dict"
 
class School(object):
 #創(chuàng)建學(xué)校

 def __init__(self,name,addr):

 self.name = name

 self.addr = addr

 def cat_school(self):
 print("學(xué)校名:【%s】\t地址:【%s】"%(self.name,self.addr))
 

 def hire_teacher(self,dict,course,teacher,file):
 #數(shù)據(jù)庫添加講師信息
 dict[self][course] = {"teacher":teacher}
 file_oper(file,"wb", dict)
 
 def create_course(self,dict,course,file):
 # 數(shù)據(jù)庫添加課程資料
 dict[self][course]={}
 file_oper(file,"wb", dict)
 def create_grade(self,dict,teacher_dict,course,grade,teacher,file1,file2):
 #數(shù)據(jù)庫添加班級信息
 dict[self][course]["grade"] = grade
 file_oper(file1, "wb", dict)
 teacher_dict[teacher] = {"grade":grade}
 file_oper(file2, "wb", teacher_dict)

class Course():
 #創(chuàng)建課程
 def __init__(self,name,price,time):
 self.name = name
 self.price = price
 self.time = time
 def cat_course(self):
 #查看課程信息
 print("課程:【%s】\t價(jià)格:【¥%s】\t周期:【%s個(gè)月】"
  %(self.name,self.price,self.time))

class Grade():
 # 創(chuàng)建班級
 def __init__(self,name,course,teacher):
 student = set([])
 self.name = name
 self.course = course
 self.teacher = teacher
 self.student = student

 

 def cat_grade(self):
 #查看班級信息
 print("班級:【%s】\t課程:【%s】\t講師:【%s】"
  %(self.name, self.course, self.teacher))

 

 def add_student(self,student_name,dict,teacher,file):
 self.student.add(student_name)
 dict[teacher]={"grade":self}
 file_oper(file, "wb", dict)

class People():
 def __init__(self,name,age):
 self.name = name
 self.age = age
class Teacher(People):
 # 創(chuàng)建講師
 def __init__(self,name,age,school,course,role="講師"):
 super(Teacher,self).__init__(name,age)
 self.role = role
 self.school = school
 self.course = course
 def cat_teacher(self):
 #查看老師資料和課程
 print('課程【%s】\t講師【%s】'%(self.course,self.name))


def file_oper(file,mode,*args):

 #數(shù)據(jù)庫寫入、讀取操作

 if mode == "wb":
 with open(file, mode) as f:
  dict = args[0]
  f.write(pickle.dumps(dict))

 if mode == "rb":
 with open(file, mode) as f:
  dict = pickle.loads(f.read())
  return dict

def information(dict,mode,*args):

 '''通過匹配mode模式,打印相應(yīng)的輸出信息'''
 if args:
 dict_info, set_info = {}, args[0]
 else:
 dict_info,set_info = {},set([])
 if dict:
 for key in dict:
  if mode == "course":
  key.cat_course()
  if mode == "main":
  key.cat_school()
  if mode == "teacher" and key == "teacher":
  dict[key].cat_teacher()
  # dict_info[key] = dict[key]
  set_info.add(dict[key].name)
  if mode == "grade" and key == "grade":
  dict[key].cat_grade()
  set_info.add(dict[key].name)
  if mode == "teacher_center":
  pass
  if type(key) != str: #key值不是字符串
  dict_info[key.name] = key
 return dict_info,set_info

 

def school_center():

 #學(xué)校管理中心

 Flag = True

 while Flag:
 dict_main = file_oper(__db_main,"rb") #主字典
 res_dict = information(dict_main,"main")[0] #打印學(xué)校信息
 school_name = input("\33[34;0m輸入要選擇的學(xué)校名\33[0m:").strip()
 if school_name in res_dict:
  school = res_dict[school_name]  #匹配選擇的學(xué)校
  while Flag:
  print("\33[32;1m歡迎進(jìn)入【%s】學(xué)校\33[0m".center(50, "*")%school.name)
  choice = options(list_school) #打印當(dāng)前選項(xiàng)
  if choice == "1":
   while True:
   print("\33[32;0m學(xué)?!?s】目前已經(jīng)有的班級信息\33[0m".center(40, "-")%school.name)
   teacher_dict = file_oper(__db_teacher,"rb")
   res_course = information(dict_main[school], "None")[0]
   set_info = set([])
   if res_course: # 打印課程與講師對應(yīng)關(guān)系
    for i in res_course:
    k = res_course[i]
    res_grade = information(dict_main[school][k], "grade",set_info)[1]
   if_cont = input("\n\33[34;0m是否要?jiǎng)?chuàng)建班級 【y】創(chuàng)建 【b】退出\33[0m:")
   if if_cont == "y":
    grade_name = input("\33[34;0m輸入要?jiǎng)?chuàng)建班級的名稱\33[0m:").strip()
    course_name = input("\33[34;0m輸入要班級要上的課程\33[0m:").strip()
    if course_name in res_course:
    course = res_course[course_name]
    if dict_main[school][course]:
     teacher = dict_main[school][course]["teacher"]
     if grade_name not in res_grade:
     grade = Grade(grade_name, course_name, teacher.name)
     school.create_grade(dict_main, teacher_dict, course, grade, teacher, __db_main,
       __db_teacher)
     else:

     print("\33[31;0m錯(cuò)誤:當(dāng)前班級已經(jīng)存在\33[0m")

    else:

     print("\33[31;0m錯(cuò)誤:當(dāng)前課程還沒有講師\33[0m")

    else:

    print("\33[31;0m錯(cuò)誤:課程【%s】不存在,請先創(chuàng)建課程\33[0m" % course_name)
   if if_cont == "b":
    break
 
  if choice == "2":
   #招聘講師
   while True:
   print("\33[32;0m學(xué)?!?s】目前已經(jīng)有的課程與講師\33[0m".center(40, "-")%school.name)
   res_course = information(dict_main[school],"None")[0]
   set_info = set([])
   if res_course:   #打印課程與講師對應(yīng)關(guān)系
    for i in res_course:
    k = res_course[i]
    res_teacher = information(dict_main[school][k], "teacher",set_info)[1]
    if not res_teacher:
     print("課程【%s】\t講師【None】" %(i))

   if_cont = input("\n\33[34;0m是否要招聘講師 【y】招聘 【b】退出\33[0m:")
   if if_cont == "y":
    teacher_name = input("\33[34;0m輸入要招聘講師的名字\33[0m:").strip()
    teacher_age = input("\33[34;0m輸入要招聘講師的年齡\33[0m:").strip()
    course_name = input("\33[34;0m輸入講師【%s】要授課的課程\33[0m:"%teacher_name).strip()
    if course_name in res_course:
     course = res_course[course_name] #創(chuàng)建講師并寫入數(shù)據(jù)庫
     if teacher_name not in res_teacher:
     teacher = Teacher(teacher_name,teacher_age,school.name,course_name)
     school.hire_teacher(dict_main, course, teacher, __db_main)
     else:
     print("\33[31;0m錯(cuò)誤:教師【%s】已經(jīng)被聘用\33[0m" %teacher_name)
    else:
    print("\33[31;0m錯(cuò)誤:課程【%s】不存在,請先創(chuàng)建課程\33[0m" %course_name)
   if if_cont == "b":
    break
  if choice == "3":
   #創(chuàng)建課程
   while True:
   print("\33[32;0m學(xué)?!?s】目前已經(jīng)有的課程\33[0m".center(40,"-")%school.name)
   res_dict = information(dict_main[school],"course")[0] #打印課程信息賦值給字典course_dict
   if_cont = input("\n\33[34;0m是否要?jiǎng)?chuàng)建課程 【y】創(chuàng)建 【b】退出\33[0m:")
   if if_cont == "y":
    course_name = input("\33[34;0m輸入要?jiǎng)?chuàng)建的課程\33[0m:").strip()
    if course_name not in res_dict: #課程不存在,創(chuàng)建
    price = input("\33[34;0m輸入課程 【%s】 的價(jià)格\33[0m:" % (course_name))
    time = input("\33[34;0m輸入課程 【%s】 的周期(月)\33[0m:" % (course_name))
    course = Course(course_name, price, time) #創(chuàng)建課程course
    school.create_course(dict_main,course, __db_main) #關(guān)聯(lián)學(xué)校和課程
    else:     #課程存在
    print("\33[31;0m錯(cuò)誤:當(dāng)前課程 【%s】 已經(jīng)存在\33[0m" % (course_name))
   if if_cont == "b":
    break
 

  if choice == "4":
   Flag = False
 if Flag:
  print("\33[31;0m錯(cuò)誤:輸入的學(xué)校 【%s】 不存在\33[0m"%(school_name))
def teacher_center():

 #講師中心

 print("\33[32;1m歡迎進(jìn)入講師中心\33[0m".center(50, "*"))
 teacher_dict = file_oper(__db_teacher, "rb")

 dict_info = information(teacher_dict,"teacher_center")[0] #驗(yàn)證登錄

 teacher_name = input("\n\33[34;0m輸入要登錄講師的名字\33[0m:").strip()

 if teacher_name in dict_info:
  while True:
  print("\33[32;1m歡迎進(jìn)入講師【%s】的管理中心\33[0m".center(40, "*")%teacher_name)
  choice = options(list_teacher)
  teacher = dict_info[teacher_name]
  grade = teacher_dict[teacher]["grade"]
  if choice == "1":
   print("\33[32;0m講師【%s】的班級信息\33[0m".center(40,"-")%teacher.name)
   print("學(xué)?!?s】\t課程【%s】\t班級【%s】\t"%(teacher.school,teacher.course,grade.name))
   any = input("\n\33[34;0m輸入任意鍵退出當(dāng)前\33[0m:")
  if choice == "2":
   print("\33[32;0m講師【%s】的班級學(xué)員列表\33[0m".center(40, "-") % teacher.name)
   print("班級【%s】\n學(xué)員【%s】"%(grade.name,grade.student))
   any = input("\n\33[34;0m輸入任意鍵退出當(dāng)前\33[0m:")
  if choice == "3":
   break
 else:
  print("\33[31;0m錯(cuò)誤:講師【%s】 不存在\33[0m"%(teacher_name))
def student_center():
 #學(xué)員中心
 print("\33[32;1m歡迎進(jìn)入學(xué)員中心中心\33[0m".center(50, "*"))
 while True:
 choice = options(list_student)  #打印學(xué)生中心選項(xiàng)
 if choice == "1":
  student_name = input("\33[34;0m輸入學(xué)員的名字\33[0m:")
  dict = file_oper(__db_main, "rb")
  teacher_dict = file_oper(__db_teacher,"rb")
  school_dict = information(dict,"main")[0] #打印當(dāng)前可選的學(xué)校
  school_name = input("\33[34;0m輸入要選擇的學(xué)校名\33[0m:").strip()
  if school_name in school_dict:
  school = school_dict[school_name]
  if dict[school]:
   course_dict = information(dict[school],"course")[0] # 打印當(dāng)前學(xué)校下的課程
   course_name = input("\33[34;0m輸入要選擇的課程\33[0m:").strip()
   if course_name in course_dict:
   course = course_dict[course_name]
   if dict[school][course].get("grade"):
    for i in teacher_dict:
    if course.name == i.course:
     teacher = i
     grade = teacher_dict[teacher]["grade"]
    print("課程【%s】的費(fèi)用為【%s】"%(course.name,course.price))
    if_pay = input("\33[34;0m是否支付當(dāng)前費(fèi)用 支付【y】\33[0m:")
    if if_pay == "y":  #上面全部匹配成功,選課成功
    grade.add_student(student_name,teacher_dict,teacher,__db_teacher)
    print("\33[31;0m選課成功\33[0m")
    any = input("\n\33[34;0m輸入任意鍵退出當(dāng)前\33[0m:")
   else:
    print("\33[31;0m錯(cuò)誤:課程沒有班級\33[0m")
   else:
   print("\33[31;0m錯(cuò)誤:課程不存在\33[0m")
  else:
   print("\33[31;0m錯(cuò)誤:當(dāng)前學(xué)校沒有課程\33[0m")
 if choice == "2":
  break

def options(list):
 #打印可選擇的操作模式,并返回選擇值
 for i, v in enumerate(list):
 print(i+1, v)
 choice = input("\33[34;0m選擇要進(jìn)入模式\33[0m:")
 return choice 

def start():
 '''程序開始'''
 while True:
 print("\33[35;1m歡迎進(jìn)入選課系統(tǒng)\33[0m".center(50, "#"))
 choice = options(list_main) #打印選項(xiàng)
 if choice == "1":
  student_center() #學(xué)生中心
 if choice == "2":
  teacher_center() #教師中心
 if choice == "3":
  school_center()  #學(xué)校中心
 if choice == "4":
  break

def init_database():
 '''數(shù)據(jù)庫初始化,不存在則創(chuàng)建,存在跳過'''
 bj = School("北京","北京市")
 sh = School("上海","上海市")
 if not os.path.exists(__db_teacher):
 dict = {bj:{},sh:{}}
 file_oper(__db_main,"wb",dict)
 if not os.path.exists(__db_teacher):
 dict = {}
 file_oper(__db_teacher,"wb",dict)

if __name__ == '__main__':
 init_database() #初始化數(shù)據(jù)庫
 list_main = ["學(xué)生中心", "講師中心", "學(xué)校中心","退出"]
 list_school = ["創(chuàng)建班級", "招聘講師", "創(chuàng)建課程","返回"]
 list_teacher = ["查看班級", "查看班級學(xué)員列表","返回" ]
 list_student = ["學(xué)員注冊","返回"]
 start()

5、程序運(yùn)行過程的簡略圖

*********************學(xué)生中心***********************

*********************講師中心***********************

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Python pandas常用函數(shù)詳解

    Python pandas常用函數(shù)詳解

    這篇文章主要介紹了Python pandas常用函數(shù)詳解,小編覺得還是挺不錯(cuò)的,具有一定借鑒價(jià)值,需要的朋友可以參考下
    2018-02-02
  • Django中如何直接執(zhí)行SQL語句

    Django中如何直接執(zhí)行SQL語句

    這篇文章主要介紹了Django中如何直接執(zhí)行SQL語句問題,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-08-08
  • 在Linux命令行中運(yùn)行Python腳本的流程步驟

    在Linux命令行中運(yùn)行Python腳本的流程步驟

    Python是一種高級編程語言,被廣泛應(yīng)用于數(shù)據(jù)科學(xué)、機(jī)器學(xué)習(xí)、Web 開發(fā)等領(lǐng)域,在Linux操作系統(tǒng)中,Python是一個(gè)默認(rèn)安裝的解釋器,用戶可以通過命令行界面(CLI)來運(yùn)行Python腳本,在本文中,我們將詳細(xì)介紹如何在Linux命令行中運(yùn)行Python腳本,需要的朋友可以參考下
    2023-11-11
  • Python字典刪除鍵值對和元素的四種方法(小結(jié))

    Python字典刪除鍵值對和元素的四種方法(小結(jié))

    刪除列表或者字符串元素的方法不止一種,同樣,刪除字典元素的方法也不止一種,本文主要介紹python中刪除字典元素的四種方法:1、使用del語句;2、使用clear();3、使用pop();4、使用popitem()。感興趣的可以了解一下
    2021-12-12
  • 淺談Django中的數(shù)據(jù)庫模型類-models.py(一對一的關(guān)系)

    淺談Django中的數(shù)據(jù)庫模型類-models.py(一對一的關(guān)系)

    今天小編就為大家分享一篇淺談Django中的數(shù)據(jù)庫模型類-models.py(一對一的關(guān)系),具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-05-05
  • Python數(shù)值求解微分方程方法(歐拉法,隱式歐拉)

    Python數(shù)值求解微分方程方法(歐拉法,隱式歐拉)

    這篇文章主要介紹了Python數(shù)值求解微分方程方法(歐拉法,隱式歐拉),文章圍繞主題展開詳細(xì)的內(nèi)介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-09-09
  • python range實(shí)例用法分享

    python range實(shí)例用法分享

    在本篇文章里小編給大家整理了關(guān)于python range實(shí)例用法,有需要的朋友們可以學(xué)習(xí)參考下
    2020-02-02
  • Python模塊搜索概念介紹及模塊安裝方法介紹

    Python模塊搜索概念介紹及模塊安裝方法介紹

    這篇文章主要介紹了Python模塊搜索概念介紹及模塊安裝方法介紹,本文詳細(xì)講解了import模塊的運(yùn)作原理,搜索路徑的過程以及模塊安裝的多種方法,需要的朋友可以參考下
    2015-06-06
  • Python實(shí)戰(zhàn)之整蠱神器合集加速友盡

    Python實(shí)戰(zhàn)之整蠱神器合集加速友盡

    讀萬卷書不如行萬里路,學(xué)的扎不扎實(shí)要通過實(shí)戰(zhàn)才能看出來,本篇文章手把手帶用python來做幾個(gè)整蠱的小程序,大家可以在過程中查缺補(bǔ)漏,看看自己掌握程度怎么樣,發(fā)給朋友加固一下友誼
    2021-10-10
  • Java多線程編程中ThreadLocal類的用法及深入

    Java多線程編程中ThreadLocal類的用法及深入

    這篇文章主要介紹了Java多線程編程中ThreadLocal類的用法及深入,嘗試了自己實(shí)現(xiàn)一個(gè)ThreadLocal類以及對相關(guān)的線程安全問題進(jìn)行討論,需要的朋友可以參考下
    2016-06-06

最新評論