Quantcast
Channel: CodeSection,代码区,Python开发技术文章_教程 - CodeSec
Viewing all articles
Browse latest Browse all 9596

从零开始学Python06作业源码(仅供参考)

$
0
0
python Version 2.7x 一,bin目录:程序启动入口 SelectLesson_start.py 1 #!usr/bin/env python 2 # -*- coding:utf-8 -*- 3 # auther:Mr.chen 4 # 描述: 5 6 7 import sys 8 sys.path.append('..') 9 from src import users_business 10 11 12 users_business.user_Main() 二,lib目录:公共模型目录 Teachers_model.py #!usr/bin/env python # -*- coding:utf-8 -*- # auther:Mr.chen # 描述:教师模型类 class teacher_Model: ''' 教师模型类 ''' def __init__(self,name,age,sex): self.Name = name #姓名 self.Age = age #年龄 self.Sex = sex #性别 self.__Calary = 0 #工资 def teacher_Accident(self): #教学事故 self.__Calary -= 10 def teacher_Success(self,cost): #教学成功 self.__Calary += int(cost) def calary_Return(self): #返回工资数据 return self.__Calary Lessons_model.py #!usr/bin/env python # -*- coding:utf-8 -*- # auther:Mr.chen # 描述: import random,time class lesson_Model: ''' 课程模型类 ''' def __init__(self,lname,lcost,tobj): self.Lname = lname #课程名 self.Lcost = lcost #课时费 self.Tobj = tobj #授课老师 self.difficulty = random.randrange(10,40) #授课难度 def classBegins(self): #上课方法 if self.success_Radio(): self.Tobj.teacher_Success(self.Lcost) return True else: self.Tobj.teacher_Accident() return False def success_Radio(self): #授课随机意外率 num = random.randrange(1, 1000) if num <= (100-self.difficulty) * 10: return True else: a = random.randrange(1, 5) # print (type(a)) lesson_Model.event(str(a)) return False @staticmethod def event(num): #授课意外事件 dict = {'1': '据说老师刚刚失恋了,授课状态很差', '2': '据说老师已经递交了辞职报告,授课状态很差', '3': '据说老师相亲去了,到现在状态都还没恢复。', '4': '据说老师家里节哀了,心情极度悲伤', '5': '据说老师钱包丢了,内心无比哀叹'} time.sleep(1) print(dict[num]) Students_model.py #!usr/bin/env python # -*- coding:utf-8 -*- # auther:Mr.chen # 描述: import random,time class student_Model: ''' 学生模型类 ''' # num = 0 def __init__(self,name,age,account,password,lobj): self.Name = name #姓名 self.Age = age #年龄 self.Account = account #账户名 self.Password = password #密码 self.Lobj = lobj #课程对象列表 self.IQ= random.randrange(40,90) #随机智商 self.schedule = {} self.num = {} for lesson in self.Lobj: self.schedule[lesson] = 0 #课程进度率字典 self.num[lesson] = 0 #课程修业次数 def Classbegins(self,lesson_name): #上课 for obj in self.Lobj: if obj.Lname == lesson_name : # print (self.num) print('{0}课程进行第{1}次修业...'.format(obj.Lname, str(self.num[obj] + 1))) time.sleep(1) if self.success_Radio(): tag = obj.classBegins() if tag: self.schedule[obj] += 20 self.num[obj] += 1 time.sleep(1) print ('你感觉非常好!') time.sleep(1) print ('{0}:{1}课程学习成功!完成率提高20%,达成率变为{2}%'.format(self.Name,obj.Lname,str(self.schedule[obj]))) else: self.num[obj] += 1 time.sleep(1) print ('你突然有一种骂娘的冲动...') time.sleep(1) print ('{0}:{1}课程学习失败,你对课程的理解没有丝毫提高,达成率为{2}%'.format(self.Name,obj.Lname,str(self.schedule[obj]))) else: tag = obj.classBegins() if tag: self.schedule[obj] += 10 self.num[obj] += 1 time.sleep(1) print('{0}:{1}课程学习欠佳!完成率提高10%,达成率变为{2}%'.format(self.Name,obj.Lname, str(self.schedule[obj]))) else: self.num[obj] += 1 time.sleep(1) print('你突然萌生了轻生的念头...') time.sleep(1) print('{0}:{1}课程学习失败,你对课程的理解没有丝毫提高,达成率为{2}%'.format(self.Name, obj.Lname, str(self.schedule[obj]))) else: pass def success_Radio(self): #学习随机意外率 num = random.randrange(1, 1000) if num <= self.IQ * 10: return True else: a = random.randrange(1,5) # print (type(a)) student_Model.event(str(a)) return False @staticmethod def event(num): #学习意外事件 dict = {'1':'你感觉头晕脑胀,浑身乏力!','2':'外面突然飞过一只蜻蜓,你看着他飞了一节课!', '3':'女朋友来短信了,你激动的忘了听课','4':'你突然感觉肚子疼...原来是想拉屎了', '5':'你的眼镜片碎了....'} time.sleep(1) print (dict[num]) common.py #!usr/bin/env python # -*- coding:utf-8 -*- # auther:Mr.chen # 描述: #!/usr/bin/python # -*- coding: utf-8 -*- # 公共方法层 import os,time,random,pickle DIR = os.path.dirname(__file__) DIR = DIR.replace('lib','db/') TAG = True #循环控制标志 def Exit(): ''' 系统退出 :return:None ''' print ('程序退出!') exit() def MD5(password): ''' 加密函数 :param firstsite: 密码字符串 :return: 加密字符串 ''' import hashlib return hashlib.md5(password).hexdigest() def Verification_input(): ''' 登录验证码校验 :return: True ''' while TAG: re = Verification_Code() code = raw_input('请输入括号里的验证码,不区分大小写({0}):'.format(re)) if code.strip().lower() != re.lower(): print('您输入的验证码有误,请重新输入!') else: return True def Verification_Code(): ''' 生成随机的6位验证码:大小写字母数字的组合 :return: 验证码 ''' code = '' b = random.randrange(0, 5) c = random.randrange(0, 5) for i in range(6): if i == b: a = random.randrange(1, 9) code = code + str(a) else: a = random.randrange(65, 90) if i == c: code = code + chr(a).lower() else: code = code + chr(a) return code def log_info_read(dir): ''' 配置文件全部读取 :param user:用户名 :return:dict字典 如果无文件返回False ''' if os.path.exists(dir): with open(dir,'r') as f: dict = pickle.load(f) return dict else: return False def log_info_write(dir,dict): ''' 配置文件全部写入 :param user:用户名 :param dict: 日志字典 :return: True or False ''' #if os.path.exists(user+'_log'): #print (DIR+user+'_log') with open(dir,'w') as f: pickle.dump(dict,f) return True 三,src目录:程序业务目录 admin_business.py #!usr/bin/env python # -*- coding:utf-8 -*- # auther:Mr.chen # 描述: import os,sys sys.path.append('..') from lib.Teachers_model import teacher_Model from lib.Lessons_model import lesson_Model from lib import common DIR = os.path.dirname(__file__) DIR = DIR.replace('src','db/') TAG = True def create_Teachers_model(): """ 创建老师模型 :return: None """ while TAG: name = raw_input("请输入老师的姓名:") age = raw_input("请输入老师的年龄:") sex = raw_input("请输入老师的性别:") while TAG: text = """ 老师信息如下: 姓名:{0} 年龄:{1} 性别:{2} """.format(name,age,sex) print (text) decide = raw_input("是否确认(y/n):") if

Viewing all articles
Browse latest Browse all 9596

Latest Images

Trending Articles