栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python小项目练习

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python小项目练习

continue student { id : id, name : name, english : english, python :python, clanguage :clanguage} studentlist.append(student) inputMark input( 是否继续添加【Y/N】 ) if inputMark Y or inputMark y : mark True else: mark False save(studentlist) print( 已保存学生信息 ) #删除学生信息 def delete(): studentlist [] mark True while(mark): ids input( 请输入要删除的ID 输入多个ID 10001,10002,10003 : ) if os.path.exists( studentInfo ): with open( studentInfo , r ) as rdInfo: studentlist rdInfo.readlines() else: print( 数据表中不存在 ) ifdel False if studentlist: with open( studentInfo , w ) as wrfile: d {} for list in studentlist: d dict(eval(list)) if ids.index( , ): for id in ids.split( , ): if not id: if d[id] ! id: wrfile.write(str(d), n ) else: if d[id] ! ids: wrfile.write(str(d), n ) else: print( 无学生信息... ) break show() inputMark input( 是否继续删除学生信息【Y/N】 ) if inputMark Y or inputMark y : mark True else: mark False #显示学生信息 def show(): student_show [] if os.path.exists( studentInfo ): with open( studentInfo , r ) as rfile: studentInfo rfile.readlines() if studentInfo: for d in studentInfo: student_show.append(dict(eval(d))) show_student(student_show) def show_student(studentlist): if not studentlist: print( 无数据 ) return format_title {:^6}{:^12}t{:^8}t{:^10}t{:^10} print(format_title.format( ID , 姓名 , 英语分数 , Python分数 , C语言分数 , 总分 )) format_data {:^6}{:^12}t{:^12}t{:^12}t{:^12} for info in studentlist: print(format_data.format(info.get( id ), info.get( name ), str(info.get( english )), str(info.get( python )), str(info.get( clanguage )), str(info.get( english ) info.get( python ) info.get( clanguage )).center(12) #修改学生信息 def modify(): show() if os.path.exists( studentInfo ): with open( studentInfo , r ) as rfile: student_old rfile.readlines() else: return sid input( 请输入要修改信息的学生ID ) with open( studentInfo , w ) as wfile: for student in student_old: d dict(eval(student)) if d[id] sid: print( 已找到ID为【 sid 】学生信息 可以修改 ) while True: try: d[ name ] input( 请输入学生姓名 ) d[ english ] float(input( 请输入英语分数 )) d[ python ] float(input( 请输入python分数 )) d[ clanguage ] float(input( 请输入C语言分数 )) except: print( 输入有误 请重新输入 ) else: break wfile.write(str(d) n ) print( 修改成功 ) else: wfile.write(student) mark input( 是否继续修改学生信息 【Y/N】 ) if mark Y or mark y : modify() else: print( 已退出修改 ) return #查询学生信息 def search(): mark True student_search [] if os.path.exists( studentInfo ): while mark: sid sname optid input( 请输入操作指令【1 按学号查询 2 按姓名查询】 ) if optid 1 : sid input( 请输入学号 ) elif optid 2 : sname input( 请输入姓名 ) else: print( 输入有误重新输入 ) with open( studentInfo , r ) as rFile: student rFile.readlines() for st in student: d dict(eval(st)) if sid is not : if d[ id ] sid: student_search.append(d) if sname is not : if d[ name ] sname: student_search.append(d) show_student(student_search) student_search.clear() inputMark input( 是否继续查询【Y/N】 ) if inputMark Y or inputMark y : mark True else: mark False else: print( 数据文件不存在 ) return #统计学生信息 def total(): if os.path.exists( StudentInfo ): with open( StudentInfo , r ) as rFile: student rFile.readlines() if student: print( 当前已录入学生信息 %d条 %len(student)) else: print( 尚未录入学生信息 ) else: print( 尚未录入学生信息 ) #按成绩排序 def sort(): show() mark True student_sort [] optsort True if os.path.exists( studentInfo ): with open( studentInfo , r ) as rFile: student rFile.readlines() for d in student : student_sort.append(dict(eval(d))) while mark: optid input( 请输入排序字段【1 按英语成绩排序 2 按Python成绩排序 3 按C语言成绩排序,4 按总成绩排序】: ) sortid input( 请输入排序方式【1 升序 2 降序】 ) if sortid 1 : optsort False elif sortid 2 : optsort True else: print( 排序方式输入有误! ) sort() if optid 1 : student_sort.sort(key lambda x:x[ english ],reverse optsort) elif optid 2 : student_sort.sort(key lambda x: x[ python ], reverse optsort) elif optid 3 : student_sort.sort(key lambda x: x[ clanguage ], reverse optsort) elif optid 4 : student_sort.sort(key lambda x: x[ english ] x[ Python ] x[ clanguage ], reverse optsort) else: print( 排序字段输入有误请重新输入 ) sort() show_student(student_sort) inputmark input( 是否重新排序【Y/N】: ) if inputmark Y or inputmark y : mark True else: mark False
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/267142.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号