威尼斯人线上娱乐

【威尼斯人线上娱乐】python职员和工人管理种类,python达成用户管理体系

16 6月 , 2019  

那是三个回顾的职工管理连串,达成最简便的功能:

python达成职工管理种类,python职员和工人处理连串

那是三个简易的职员和工人管理种类,达成最简易的服从:

1.登入用户密码验证(错误壹遍活动退出)
2.支撑文本职员和工人的探求、增多、删除、修改
3.顶级层级五个采纳、二级层级八个选项,都帮助判空、退出、重返上一层级
4.针对删除和改造有职员和工人当前机关找出到的结果进行参照他事他说加以考察修改和特种提示是不是删除

用到的底子知识点相比较多:

1.计数器
2.while True 以及给while做退出层级标识
3.if…elif…else 的嵌套使用
4.continue 和 break 以及轻便函数定义def
5.键盘抓取 raw_input 以及通过
os.system(‘clear’)来调用linux中shell下的指令。
6.文本的读取写入原理(单读的不可能实际写入,只好通过转存文本覆盖写入。)
设若是‘a+’则只为读取并可通过’writelines()’来写入,是增添写入
假定是‘w+’则为写入,可通过‘writelines()’来写入,是覆盖写入
7.列表的组合原理,列表的退换,列表的定位以及下标获取
listname.index(line)
8.特意须求专注程序实行前后相继以及严峻的缩进格式

威尼斯人线上娱乐 1

#!/usr/bin/env python
# _*_ coding:utf-8 _*_
import sys
import os

#系统的用户登录
#os.system('clear')
time = 0
while True: #this is login
  if time < 3:
    name = raw_input("\033[1mplease input your login account:").strip()
    passwd = raw_input("\033[1mplease input your login password:").strip()
    if len(name) == 0:        #.strip()意为去除空格
      print("\033[31mIt's not allow empty input!\n")
      continue
    elif name == 'zhangjun' and passwd == '123.com':
      print("\033[32mYour account and password right!")
      pass
    else:
      print("\033[31mYour account or password error!")
      time += 1
      continue
    break
  else:
    print("\033[31mYou are wrong three times, has already quit from the system!")
    sys.exit()

#系统的选择界面
#os.system('clear')
print ('\n')
def display(): #进行登陆后界面的函数定义,方便在下面的选用层级后,返回上一层时,依然可以看到选择大屏。
 print("\033[34m########################################################################")
 print("\033[34m\t######### \033[1;32mWelcome to this employee search system!\033[0;34m #########")
 print("\033[34m\t\t#################################################")
 print("\n")
 print("\033[32m\033[1m\t\t\t1\033[33m\033[1m.Search.(you can search the infomation for employee!)\n")
 print("\033[32m\033[1m\t\t\t2\033[33m\033[1m.Add.(Add a user into this employee system!)\n")
 print("\033[32m\033[1m\t\t\t3\033[33m\033[1m.Delete.(Delete a user from this employee system!)\n")
 print("\033[32m\033[1m\t\t\t4\033[33m\033[1m.Modify.(You can modify something infomation in this employee system!)\n")
 print("\033[32m\033[1m\t\t\t5\033[33m\033[1m.Quit.(quit this employee system!)\n")
 print("\n")
 dict ()
#指定文件路径
path = 'D:\Users\Franzhang\employee_list.txt'
#定义while层级标记break_tag1 = 0 以及登陆初始提示
break_tag1 = 0
while break_tag1 == 0:
 display()
 select_input = raw_input ("\033[37m\033[1mplease input you want to select items:").strip ()
 if len(select_input) == 0:
  continue
 elif select_input == 'quit':
  sys.exit ()
 #选项1进行模糊搜索
 elif int(select_input) == 1:
  # os.system('clear')
  break_tag2 = 0
  while break_tag2 == 0:
   content_open = open (path)
   search_input = raw_input ("please input your need (SEARCH MODE):").strip ()
   for line in content_open:
    if len (search_input) == 0:
     continue
    elif search_input in line:
     print line
    else:
     if search_input == 'all': #展示文本目前所有员工
      print line
     elif search_input == 'quit':
      break_tag2 = 1 #返回上一层级选择项
 #选项2进行员工信息添加(其实是添加了一行列表)
 elif int(select_input) == 2:
  # os.system('clear')
  content_write = file (path, 'a+') #读入文本
  break_tag3 = 0
  while break_tag3 == 0:
   addid_input = raw_input ("please input your need (ADD_ID):").strip ()
   if len (addid_input) == 0:
    continue
   elif addid_input == 'quit':
    break_tag3 = 1
    content_write.close () #文本使用完毕后需要关闭,以免占用内存。
    break
   addname_input = raw_input ("please input your need (ADD_NAME):").strip ()
   if len (addid_input) == 0:
    continue
   elif addname_input == 'quit':
    break_tag3 = 1
    content_write.close ()
    break
   addage_input = raw_input ("please input your need (ADD_AGE):").strip ()
   if len (addid_input) == 0:
    continue
   elif addage_input == 'quit':
    break_tag3 = 1
    content_write.close ()
    break
   adddpt_input = raw_input ("please input your need (ADD_DPT):").strip ()
   if len (addid_input) == 0:
    continue
   elif adddpt_input == 'quit':
    break_tag3 = 1
    content_write.close ()
    break
   addphone_input = raw_input ("please input your need (ADD_phone):").strip ()
   if len (addid_input) == 0:
    continue
   elif addphone_input == 'quit':
    break_tag3 = 1
    content_write.close ()
    break
   list_add = [addid_input, '\t', addname_input, '\t', addage_input, '\t', adddpt_input, '\t', addphone_input,'\n'] #将上面的单项录入写入列表list_add
   content_write.writelines (list_add) #将列表追加写入文本
   print("It's already insert the list!")
   continue
 #选项3进行员工删除
 elif int(select_input) == 3:
  # os.system('clear')
  break_tag4 = 0
  while break_tag4 == 0:
   content_opend = open (path)
   delete_input = raw_input ("please input your need (DELETE):").strip ()
   if len (delete_input) == 0:
    continue
   elif delete_input == 'quit':
    break_tag4 = 1
   for line in content_opend:
    if delete_input in line:
     print line
     sure = raw_input ("Are you sure delete this account line ? (yes/no):").strip ()
     if len (sure) == 0:
      continue
     elif sure == 'yes':
      inside = file (path, 'a+') 
      bebe = inside.readlines () #按行读入文本并转换为列表data
      data = list (bebe) 
      for i in data:
       if delete_input in i: 
        w = data.index (i) #获取输入的员工在整个文本列表的位置
        del data[w] #删除单行
      data_in = data #转存删除后的文本列表(这个时候被读取的经过删除后的内容还在内存中。)
      inside.close () #转存后在关闭文本,否则导致转存因提前关闭而无效。
      inside_w = file (path, 'w+') #再次以覆盖写入方式读取文本
      inside_w.writelines (data_in) #将刚才转存的文本写入
      inside_w.close () #关闭文本后会自动保存写入
      break
     elif sure == 'no':
      break
    continue
 #选项4进行员工信息更改(整条员工信息的更改)
 elif int(select_input) == 4:
  break_tag5 = 0
  while break_tag5 == 0:
   modify_input = raw_input ("please input your modify item:").strip ()
   if len (modify_input) == 0:
    continue
   elif modify_input == 'quit':
    break
   content_modify = file (path, 'a+')
   modify_line = content_modify.readlines ()
   modata = list (modify_line)
   for i in modata:
    if modify_input in i:
     ms = modata.index (i)#获取输入变量的最终列表定位
     print i
     mosure = raw_input ("Are you sure to change this user ? (yes/no):").strip ()
     if len (mosure) == 0:
      continue
     elif mosure == 'yes':
      break_tag6 = 0
      while break_tag6 == 0:
       sureid_input = raw_input ("please input you will change this user id: ").strip ()
       if len(sureid_input) == 0:
        continue
       elif sureid_input == 'quit':
        break
       surename_input = raw_input ("please input you will change this user name:").strip ()
       if len(surename_input) == 0:
        continue
       elif surename_input == 'quit':
        sureid_input = None #此处赋空值,为了防止中途退出,而出现个别写入
        surename_input = None
        break
       sureage_input = raw_input ("please input you will change this user age:").strip ()
       if len(sureage_input) == 0:
        continue
       elif sureage_input == 'quit':
        sureid_input = None
        surename_input = None
        sureage_input = None
        break
       suredep_input = raw_input ("please input you will change this user department:").strip ()
       if len(suredep_input) == 0:
        continue
       elif suredep_input == 'quit':
        sureid_input = None
        surename_input = None
        sureage_input = None
        suredep_input = None
        break
       surephone_input = raw_input ("please input you will change this user phone:").strip ()
       if len(surephone_input) == 0:
        continue
       elif surephone_input == 'quit':
        sureid_input = None
        surename_input = None
        sureage_input = None
        suredep_input = None
        surephone_input = None
        break
       later_sure = [sureid_input, '\t', surename_input, '\t\t', sureage_input, '\t', suredep_input,'\t', surephone_input, '\n']#将上面的值放入列表
       del modata[ms] #当整个输入完成以后再进行删除,防止中途退出未完成状体的删除。
       modata_one = modata
       content_modify.close () #这里还是使用了删除、转存、重新写入的原理
       content_modify_list = file (path, 'w+')
       content_modify_list.writelines (modata_one)
       content_modify_list.close ()
       content_modify_list_one = file (path, 'a+')
       content_modify_list_one.writelines (later_sure)
       content_modify_list_one.close ()
       break
     elif mosure == 'quit' or 'no':
      break
 elif int (select_input) == 5:
  print("Thank you for use this employee system, write by franzhang!")
  sys.exit()

employee_list.txt:

威尼斯人线上娱乐 2

越多学学材质请关心专项论题《管理连串开拓》。

上述正是本文的全部内容,希望对大家的求学抱有援救,也期待大家多多帮忙帮客之家。

那是二个简便的职工管理连串,达成最简便的功能:
1.登入用户密码验证(错误三次机关退出)…

【威尼斯人线上娱乐】python职员和工人管理种类,python达成用户管理体系。正文实例为大家享受了Python实现学生战绩管理种类的现实性代码,供我们参照他事他说加以侦查,具体内容如下

本文实例为我们享受了python达成用户处理类其他现实代码,供我们参谋,具体内容如下

1.登入用户密码验证(错误贰次活动退出)
2.支持文本职员和工人的检索、加多、删除、修改
3.超级层级多个挑选、二级层级多少个挑选,都帮助判空、退出、重临上一层级
4.针对删除和修改有职工当前机动物检疫索到的结果开始展览参照他事他说加以考查修改和卓绝提示是不是删除

基本成效:

《python焦点编制程序》第七章演习题第五题

用到的底子知识点相比多:

输入并蕴藏学生的音讯:通过输入学生的学号、姓名、和分数,然后就足以把数据保存在创设的student文件之中。

一、标题叙述

1.计数器
2.while True 以及给while做退出层级标识
3.if…elif…else 的嵌套使用
4.continue 和 break 以及轻巧函数定义def
5.键盘抓取 raw_input 以及因此os.system(‘clear’)来调用linux中shell下的命令。
6.文本的读取写入原理(单读的不可能实际写入,只可以通过转存文本覆盖写入。)
假假诺‘a+’则只为读取并可因而’writelines()’来写入,是充实写入
若是是‘w+’则为写入,可通过‘writelines()’来写入,是覆盖写入
7.列表的组成原理,列表的更动,列表的一定以及下标获取
listname.index(line)
8.特地供给专注程序施行前后相继以及严苛的缩进格式

打字与印刷学生的兼具消息:通过贰个打字与印刷函数就足以把具有的新闻打字与印刷在荧屏上。

 userpw2.py。上边包车型客车主题材料和例题7.第11中学的管理名字-密码的键值对数码程序有关。

威尼斯人线上娱乐 3

修改学生信息:这些效应首先通过询问效率查询出该学员是或不是留存,假若存在就对该学生的消息实行改造,倘若不设有则赶回到主分界面。

(a)
修改十二分剧本,使她能记录用户上次的登入日期和岁月(用time模块),并与用户密码一齐保存起来。程序的分界面供给用户输入用户名和密码的唤起。无论用户名是还是不是登入成功,都应当提醒,在用户登录成功后,应立异相应用户的上次登录时间戳。假诺本次登录与上次登录在时刻上偏离不当先多少个钟头,则通知该用户:“You
already in at :<last_login_timestamp>”。

#!/usr/bin/env python
# _*_ coding:utf-8 _*_
import sys
import os

#系统的用户登录
#os.system('clear')
time = 0
while True: #this is login
  if time < 3:
    name = raw_input("\033[1mplease input your login account:").strip()
    passwd = raw_input("\033[1mplease input your login password:").strip()
    if len(name) == 0:        #.strip()意为去除空格
      print("\033[31mIt's not allow empty input!\n")
      continue
    elif name == 'zhangjun' and passwd == '123.com':
      print("\033[32mYour account and password right!")
      pass
    else:
      print("\033[31mYour account or password error!")
      time += 1
      continue
    break
  else:
    print("\033[31mYou are wrong three times, has already quit from the system!")
    sys.exit()

#系统的选择界面
#os.system('clear')
print ('\n')
def display(): #进行登陆后界面的函数定义,方便在下面的选用层级后,返回上一层时,依然可以看到选择大屏。
 print("\033[34m########################################################################")
 print("\033[34m\t######### \033[1;32mWelcome to this employee search system!\033[0;34m #########")
 print("\033[34m\t\t#################################################")
 print("\n")
 print("\033[32m\033[1m\t\t\t1\033[33m\033[1m.Search.(you can search the infomation for employee!)\n")
 print("\033[32m\033[1m\t\t\t2\033[33m\033[1m.Add.(Add a user into this employee system!)\n")
 print("\033[32m\033[1m\t\t\t3\033[33m\033[1m.Delete.(Delete a user from this employee system!)\n")
 print("\033[32m\033[1m\t\t\t4\033[33m\033[1m.Modify.(You can modify something infomation in this employee system!)\n")
 print("\033[32m\033[1m\t\t\t5\033[33m\033[1m.Quit.(quit this employee system!)\n")
 print("\n")
 dict ()
#指定文件路径
path = 'D:\Users\Franzhang\employee_list.txt'
#定义while层级标记break_tag1 = 0 以及登陆初始提示
break_tag1 = 0
while break_tag1 == 0:
 display()
 select_input = raw_input ("\033[37m\033[1mplease input you want to select items:").strip ()
 if len(select_input) == 0:
  continue
 elif select_input == 'quit':
  sys.exit ()
 #选项1进行模糊搜索
 elif int(select_input) == 1:
  # os.system('clear')
  break_tag2 = 0
  while break_tag2 == 0:
   content_open = open (path)
   search_input = raw_input ("please input your need (SEARCH MODE):").strip ()
   for line in content_open:
    if len (search_input) == 0:
     continue
    elif search_input in line:
     print line
    else:
     if search_input == 'all': #展示文本目前所有员工
      print line
     elif search_input == 'quit':
      break_tag2 = 1 #返回上一层级选择项
 #选项2进行员工信息添加(其实是添加了一行列表)
 elif int(select_input) == 2:
  # os.system('clear')
  content_write = file (path, 'a+') #读入文本
  break_tag3 = 0
  while break_tag3 == 0:
   addid_input = raw_input ("please input your need (ADD_ID):").strip ()
   if len (addid_input) == 0:
    continue
   elif addid_input == 'quit':
    break_tag3 = 1
    content_write.close () #文本使用完毕后需要关闭,以免占用内存。
    break
   addname_input = raw_input ("please input your need (ADD_NAME):").strip ()
   if len (addid_input) == 0:
    continue
   elif addname_input == 'quit':
    break_tag3 = 1
    content_write.close ()
    break
   addage_input = raw_input ("please input your need (ADD_AGE):").strip ()
   if len (addid_input) == 0:
    continue
   elif addage_input == 'quit':
    break_tag3 = 1
    content_write.close ()
    break
   adddpt_input = raw_input ("please input your need (ADD_DPT):").strip ()
   if len (addid_input) == 0:
    continue
   elif adddpt_input == 'quit':
    break_tag3 = 1
    content_write.close ()
    break
   addphone_input = raw_input ("please input your need (ADD_phone):").strip ()
   if len (addid_input) == 0:
    continue
   elif addphone_input == 'quit':
    break_tag3 = 1
    content_write.close ()
    break
   list_add = [addid_input, '\t', addname_input, '\t', addage_input, '\t', adddpt_input, '\t', addphone_input,'\n'] #将上面的单项录入写入列表list_add
   content_write.writelines (list_add) #将列表追加写入文本
   print("It's already insert the list!")
   continue
 #选项3进行员工删除
 elif int(select_input) == 3:
  # os.system('clear')
  break_tag4 = 0
  while break_tag4 == 0:
   content_opend = open (path)
   delete_input = raw_input ("please input your need (DELETE):").strip ()
   if len (delete_input) == 0:
    continue
   elif delete_input == 'quit':
    break_tag4 = 1
   for line in content_opend:
    if delete_input in line:
     print line
     sure = raw_input ("Are you sure delete this account line ? (yes/no):").strip ()
     if len (sure) == 0:
      continue
     elif sure == 'yes':
      inside = file (path, 'a+') 
      bebe = inside.readlines () #按行读入文本并转换为列表data
      data = list (bebe) 
      for i in data:
       if delete_input in i: 
        w = data.index (i) #获取输入的员工在整个文本列表的位置
        del data[w] #删除单行
      data_in = data #转存删除后的文本列表(这个时候被读取的经过删除后的内容还在内存中。)
      inside.close () #转存后在关闭文本,否则导致转存因提前关闭而无效。
      inside_w = file (path, 'w+') #再次以覆盖写入方式读取文本
      inside_w.writelines (data_in) #将刚才转存的文本写入
      inside_w.close () #关闭文本后会自动保存写入
      break
     elif sure == 'no':
      break
    continue
 #选项4进行员工信息更改(整条员工信息的更改)
 elif int(select_input) == 4:
  break_tag5 = 0
  while break_tag5 == 0:
   modify_input = raw_input ("please input your modify item:").strip ()
   if len (modify_input) == 0:
    continue
   elif modify_input == 'quit':
    break
   content_modify = file (path, 'a+')
   modify_line = content_modify.readlines ()
   modata = list (modify_line)
   for i in modata:
    if modify_input in i:
     ms = modata.index (i)#获取输入变量的最终列表定位
     print i
     mosure = raw_input ("Are you sure to change this user ? (yes/no):").strip ()
     if len (mosure) == 0:
      continue
     elif mosure == 'yes':
      break_tag6 = 0
      while break_tag6 == 0:
       sureid_input = raw_input ("please input you will change this user id: ").strip ()
       if len(sureid_input) == 0:
        continue
       elif sureid_input == 'quit':
        break
       surename_input = raw_input ("please input you will change this user name:").strip ()
       if len(surename_input) == 0:
        continue
       elif surename_input == 'quit':
        sureid_input = None #此处赋空值,为了防止中途退出,而出现个别写入
        surename_input = None
        break
       sureage_input = raw_input ("please input you will change this user age:").strip ()
       if len(sureage_input) == 0:
        continue
       elif sureage_input == 'quit':
        sureid_input = None
        surename_input = None
        sureage_input = None
        break
       suredep_input = raw_input ("please input you will change this user department:").strip ()
       if len(suredep_input) == 0:
        continue
       elif suredep_input == 'quit':
        sureid_input = None
        surename_input = None
        sureage_input = None
        suredep_input = None
        break
       surephone_input = raw_input ("please input you will change this user phone:").strip ()
       if len(surephone_input) == 0:
        continue
       elif surephone_input == 'quit':
        sureid_input = None
        surename_input = None
        sureage_input = None
        suredep_input = None
        surephone_input = None
        break
       later_sure = [sureid_input, '\t', surename_input, '\t\t', sureage_input, '\t', suredep_input,'\t', surephone_input, '\n']#将上面的值放入列表
       del modata[ms] #当整个输入完成以后再进行删除,防止中途退出未完成状体的删除。
       modata_one = modata
       content_modify.close () #这里还是使用了删除、转存、重新写入的原理
       content_modify_list = file (path, 'w+')
       content_modify_list.writelines (modata_one)
       content_modify_list.close ()
       content_modify_list_one = file (path, 'a+')
       content_modify_list_one.writelines (later_sure)
       content_modify_list_one.close ()
       break
     elif mosure == 'quit' or 'no':
      break
 elif int (select_input) == 5:
  print("Thank you for use this employee system, write by franzhang!")
  sys.exit()

删除学生音信:该意义是对相应的学习者开展删除操作,假若学生存在就查找到实行删减。

(b) 增添一个管理菜单,当中有以下两项:(1)删除二个用户
(2)展现系统中具有用户的名字和他们密码的清单。

employee_list.txt:

按学生成绩举行排序:
这些效应是依照学生的成就进行排序,对学生的音讯进行操作。

(c) 口令近来尚无加密。请加多一段对唱令加密的代码

威尼斯人线上娱乐 4

探索学生音讯:那个功能通过输入学号,查找该学员的信息,假诺有该学号就输出该学生的新闻,未有该学号就提示输入的学号不设有。

(d)
为程序增多图形分界面,举例,用Tkinter。(图形化分界面开拓比较复杂,这里没有用到。)

愈来愈多学学资料请关怀专项论题《管理体系开采》。

开端化效能

(e) 必要用户名布区分轻重缓急写。

如上便是本文的全部内容,希望对我们的读书抱有支持,也指望我们多多帮衬脚本之家。

系统在开班使用之前先进行开端化作用,判别students.txt文件中是或不是保存的有学童的信息,要是有就把公文的内容读收取来,供接下来的操作使用,如用未有就发轫化一个空的列表,用来保存用户的输入,程序中接下去的具有数据都会保留在该列表中极度与一个数量缓冲区。

(f ) 坚实对用户名的界定,差异意符号和空白符。

您大概感兴趣的稿子:

  • python用户管理类别的实例解说
  • Python达成GUI学生新闻保管体系
  • python完毕用户管理体系
  • python完成外送食品音信保管连串
  • python完毕学生管理连串
  • python版学生管理种类
  • Python完成学生成绩管理种类
  • Python学生成绩管理种类简洁版
  • Python达成学校处理种类
  • Python学生音信保管种类修改版

第一是开辟文件操作,对文件中的内容展开读取操作,由于在文书中保存的内容是由空格实行划分的,并且每三个学员的新闻都占领一行,首先读出富有的原委,先进行根据换行实行剪切,获得各类人的新闻,然后再对各种人的新闻进行安装空格分隔,获得各样人的详细信息包涵用户的全名,学号,战表。

(g)
合并“新用户”和“老用户”五个挑选。假设贰个新用户试图用一个不设有的用户名登入,询问该用户是不是是新用户,倘诺是必定的,就创办该用户。不然按老用户的方法登录。

def Init(stulist): #初始化函数 
 print "初始化......" 
 file_object = open('students.txt', 'r') 
 for line in file_object: 
  stu = Student() 
  line = line.strip("\n") 
  s = line.split(" ") 
  stu.ID = s[0] 
  stu.name = s[1] 
  stu.score = s[2] 
 stulist.append(stu) 
print "初始化成功!" 

二、程序中用到的模块,解释如下:

作育排序达成

(1) re:正则表明式引擎,python中调用正则表明式的艺术

这一部分代码是依据学生战表的高低举行排序,在完毕的时候,首先是把全体人的大成放到贰个列表里面然后使用插入排序,依据战表的轻重缓急对StuList中保留的学习者音信的地址进行排序

(2) pickle:对象悠久化,将数据写入到磁盘中

def Sort(stulist): #按学生成绩排序
 Stu = []
 sum_count = []
 for li in stulist:
 temp = []
 temp.append(li.ID)
 temp.append(li.name)
 temp.append(int(li.score1))
 temp.append(int(li.score2))
 temp.append(int(li.score3))
 temp.append(int(li.sum))
 sum_count.append(int(li.sum))
 Stu.append(temp)

 #print sum_count
 #print Stu;
 #print stulist
 insertSort(sum_count, stulist)
 #print stulist;
 display(stulist)

def insertSort(a, stulist): 
 for i in range(len(a)-1): 
 #print a,i 
 for j in range(i+1,len(a)): 
  if a[i]<a[j]: 
  temp = stulist[i] 
  stulist[i] = stulist[j] 
  stulist[j] = temp

(3) datetime:时间拍卖,用于记录用户登录时间戳

分界面截图如下:

(4) base64:base64加密模块

威尼斯人线上娱乐 5

(5) hashlib:hash加密模块 

威尼斯人线上娱乐,源码:

完全代码:

# -*- coding: UTF-8 -*-

import os
import re
import numpy as np

class Student: #定义一个学生类
 def __init__(self):
 self.name = ''
 self.ID =''
 self.score1 = 0
 self.score2 = 0
 self.score1 = 0
 self.sum = 0


def searchByID(stulist, ID): #按学号查找看是否学号已经存在
 for item in stulist:
 if item.ID == ID:
  return True

def Add(stulist,stu): #添加一个学生信息
 if searchByID(stulist, stu.ID) == True:
 print"学号已经存在!"
 return False
 stulist.append(stu)
 print stu.name,stu.ID, stu.score1, stu.score2, stu.score3, stu.sum;
 print "是否要保存学生信息?"
 nChoose = raw_input("Choose Y/N")
 if nChoose == 'Y' or nChoose == 'y':
 file_object = open("students.txt", "a")
 file_object.write(stu.ID)
 file_object.write(" ")
 file_object.write(stu.name)
 file_object.write(" ")
 file_object.write(str(stu.score1))
 file_object.write(" ")
 file_object.write(str(stu.score2))
 file_object.write(" ")
 file_object.write(str(stu.score3))
 file_object.write(" ")
 file_object.write(str(stu.sum))
 file_object.write("\n")
 file_object.close()
 print u"保存成功!"

def Search(stulist, ID): #搜索一个学生信息
 print u"学号 姓名 语文 数学 英语 总分"
 count = 0
 for item in stulist:
 if item.ID == ID:
  print item.ID, '\t' ,item.name,'\t', item.score1,'\t',item.score2, '\t', item.score3, '\t',item.sum
  break
 count = 0
 if count == len(stulist):
 print "没有该学生学号!"

def Del(stulist, ID): #删除一个学生信息
 count = 0
 for item in stulist:
 if item.ID == ID:
  stulist.remove(item)
  print "删除成功!"
  break
 count +=1
 # if count == len(stulist):
 # print "没有该学生学号!"
 file_object = open("students.txt", "w")
 for stu in stulist:
 print stu.ID, stu.name, stu.score1,stu.score2, stu.score3, stu.sum
 file_object.write(stu.ID)
 file_object.write(" ")
 file_object.write(stu.name)
 file_object.write(" ")
 file_object.write(str(stu.score1))
 file_object.write(" ")
 file_object.write(str(stu.score2))
 file_object.write(" ")
 file_object.write(str(stu.score3))
 file_object.write(" ")
 file_object.write(str(stu.sum))
 file_object.write("\n")
 file_object.close()
 # print "保存成功!"
 file_object.close()
def Change(stulist, ID):
 count = 0
 for item in stulist:
 if item.ID == ID:
  stulist.remove(item)
  file_object = open("students.txt", "w")
  for stu in stulist:
  #print li.ID, li.name, li.score
  file_object.write(stu.ID)
  file_object.write(" ")
  file_object.write(stu.name)
  file_object.write(" ")
  file_object.write(str(stu.score1))
  file_object.write(" ")
  file_object.write(str(stu.score2))
  file_object.write(" ")
  file_object.write(str(stu.score3))
  file_object.write(" ")
  file_object.write(str(stu.sum))
  file_object.write("\n")
  # print "保存成功!"
  file_object.close()
  stu = Student()
  stu.name = raw_input("请输入学生的姓名")
  while True:
  stu.ID = raw_input("请输入学生的ID")
  p = re.compile('^[0-9]{3}$')
  if p.match(stu.ID):
   break
  else:
   print "输入的有错误!"
  while True:
  stu.score1 = int(raw_input("请输入学生语文成绩"))
  if stu.score1 <= 100 and stu.score1 > 0 :
   break
  else:
   print "输入的学生成绩有错误!"
  while True:
  stu.score2 = int(raw_input("请输入学生数学成绩"))
  if stu.score2 <= 100 and stu.score2 > 0 :
   break
  else:
   print "输入的学生成绩有错误!"
  while True:
  stu.score3 = int(raw_input("请输入学生英语成绩"))
  if stu.score3 <= 100 and stu.score3 > 0 :
   break
  else:
   print "输入的学生成绩有错误!"
  stu.sum = stu.score1 + stu.score2 + stu.score3
  Add(stulist,stu)
def display(stulist): #显示所有学生信息
 print u"学号 姓名 语文 数学 英语 总分"
 for item in stulist:
 print item.ID, '\t' ,item.name,'\t', item.score1,'\t',item.score2, '\t', item.score3, '\t',item.sum

def Sort(stulist): #按学生成绩排序
 Stu = []
 sum_count = []
 for li in stulist:
 temp = []
 temp.append(li.ID)
 temp.append(li.name)
 temp.append(int(li.score1))
 temp.append(int(li.score2))
 temp.append(int(li.score3))
 temp.append(int(li.sum))
 sum_count.append(int(li.sum))
 Stu.append(temp)

 #print sum_count
 #print Stu;
 #print stulist
 insertSort(sum_count, stulist)
 #print stulist;
 display(stulist)

def insertSort(a, stulist): 
 for i in range(len(a)-1): 
 #print a,i 
 for j in range(i+1,len(a)): 
  if a[i]<a[j]: 
  temp = stulist[i] 
  stulist[i] = stulist[j] 
  stulist[j] = temp 
 #return a 

def Init(stulist): #初始化函数
 print "初始化......"
 file_object = open('students.txt', 'r')
 for line in file_object:
 stu = Student()
 line = line.strip("\n")
 s = line.split(" ")
 stu.ID = s[0]
 stu.name = s[1]
 stu.score1 = s[2]
 stu.score2 = s[3]
 stu.score3 = s[4]
 stu.sum = s[5]
 stulist.append(stu)
 file_object.close()
 print "初始化成功!"
 main()

def main(): #主函数 该程序的入口函数
 while True:
 print "*********************"
 print u"--------菜单---------"
 print u"增加学生信息--------1"
 print u"查找学生信息--------2"
 print u"删除学生信息--------3"
 print u"修改学生信息--------4"
 print u"所有学生信息--------5"
 print u"按照分数排序--------6"
 print u"退出程序------------0"
 print "*********************"

 nChoose = raw_input("请输入你的选择:")
 if nChoose == "1":
  stu = Student()
  stu.name = raw_input("请输入学生的姓名")
  while True:
  stu.ID = raw_input("请输入学生的ID")
  p = re.compile('^[0-9]{3}$')
  if p.match(stu.ID):
   break
  else:
   print "输入的有错误!"
  while True:
  stu.score1 = int(raw_input("请输入学生语文成绩"))
  if stu.score1 <= 100 and stu.score1 > 0 :
   break
  else:
   print "输入的学生成绩有错误!"
  while True:
  stu.score2 = int(raw_input("请输入学生数学成绩"))
  if stu.score2 <= 100 and stu.score2 > 0 :
   break
  else:
   print "输入的学生成绩有错误!"
  while True:
  stu.score3 = int(raw_input("请输入学生英语成绩"))
  if stu.score3 <= 100 and stu.score3 > 0 :
   break
  else:
   print "输入的学生成绩有错误!"
  stu.sum = stu.score1 + stu.score2 + stu.score3
  Add(stulist,stu)

 if nChoose == '2':
  ID = raw_input("请输入学生的ID")
  Search(stulist, ID)

 if nChoose == '3':
  ID = raw_input("请输入学生的ID")
  Del(stulist, ID)
 if nChoose == '4':
  ID = raw_input("请输入学生的ID")
  Change(stulist, ID)

 if nChoose == '5':
  display(stulist)

 if nChoose == '6':
  Sort(stulist)


 if nChoose == '0':
  break

if __name__ == '__main__':
 stulist =[]
Init(stulist)
#-*- coding:utf-8 -*- 
#2017.7.17

import re 
import pickle 
import base64,hashlib 
from datetime import datetime 

def Initialization(file_name): 
 '''''程序初始化,创建user.ini和time.ini文件''' 
 dict_test={'admin':'db69fc039dcbd2962cb4d28f5891aae1'} #创建超级管理员,默认密码为admin 
 f = file(file_name,'a+') #以追加的方式打开文件,避免文件被修改 
 if len(f.readlines()) ==0: #判断程序是否为空,只在第一次运行的时候初始化 
  if file_name=='user.ini': 
   pickle.dump(dict_test, f, True) 
  else: 
   pickle.dump({},f, True) 
 f.close() 

def encodepass(passwd): 
 '''''采用base64和md5双层加密,破解可能几乎为0''' 
 m = hashlib.md5() 
 pwd = base64.b64encode(passwd) 
 m.update(pwd) 
 return m.hexdigest() 

def time_order(user): 
 '''''记录用户登陆时间,结果保存在time.ini文件中''' 
 ft = file('time.ini','r') 
 dbt = pickle.load(ft) 
 if user not in dbt: 
  dbt.setdefault(user,datetime.today()) 
 else: 
  time_value = dbt[user] 
  t = datetime.today()-time_value 
  try: 
   if t.hour<=4: 
    print 'You already logged in at:<last_login_timestamp>' 
  except: 
   print 'You already logged in at:<last_login_timestamp>' 
  dbt[user] = datetime.today() 
 ft = file('time.ini','w') 
 pickle.dump(dbt, ft, True) 
 ft.close() 


def newuser(db): 
 '''''用户创建程序,由olduser调用''' 
 while True: 
  name = raw_input('Please input the username:') 
  if re.match(r'\w', name): #采用正则表达式检测用户名是否合法 
   pass 
  else: 
   print 'Username should be made of A~Z、a~z、0~9、_' 
   continue 
  for valuename in db.keys(): 
   if name.lower() == valuename.lower(): 
    break 
  else: 
   break 
 passwd = raw_input('Please input the password:') 
 db[name] = encodepass(passwd) 

def olduser(db): 
 '''''用户登陆程序''' 
 name = raw_input('Login:') 
 if name in db: 
  pwd = raw_input('passwd:') 
  passwd = db.get(name) 
  if passwd == encodepass(pwd): 
   print 'Welcome back!',name 
   time_order(name) 
  else: 
   print 'Login incorrent!' 
 else: 
  YN = raw_input('Do you want to instead a new user? Yes or No:') 
  if YN.lower()=='yes': 
   newuser(db) 
 print '\n', 

def deluser(db): 
 '''''删除一个用户,但必须以管理员的身份''' 
 print 'Please login as admin' #管理员的身份才能删除用户 
 name = raw_input('Login:') 
 pwd = raw_input('passwd:') 
 passwd = db.get(name) 
 if passwd == encodepass(pwd) and name=='admin': 
  user = raw_input('Please input a user name:') 
  if user != 'admin': 
   if db.pop(user): 
    print 'Delete Current!' 
  else: 
   print 'Con not delete admin!' 
 else: 
  print 'Wrong passwprd' 

def checkuser(db): 
 '''''查看所有用户,但必须以管理员的身份''' 
 print 'Please login as admin' #管理员的身份才能查看所有用户 
 name = raw_input('Login:') 
 pwd = raw_input('passwd:') 
 passwd = db.get(name) 
 if passwd == encodepass(pwd) and name == 'admin': 
  for key in db: 
   print 'username: %10s ====> password: %10s' % (key,db[key]) 
 else: 
  print 'You can not check all users!' 

def resetuser(db): 
 '''''修改密码,但必须正确的输入老密码''' 
 name = raw_input('Please input the username:') 
 passwd = raw_input('Please input old password:') 
 if db[name] == encodepass(passwd): 
  passwd = raw_input('Please input new password:') 
  db[name] = encodepass(passwd) 
 else: 
  print 'Wrong password!' 

def showmenu(): 
 '''''程序运行的主函数''' 
 fu = file('user.ini','r') 
 db = pickle.load(fu) 
 prompt = '''''(L)ogin Now
(Q)uit
(D)elet User
(C)heck All User
(R)eset Password
Enter choice:''' 

 done = False 
 while not done: 
  chosen = False 
  while not chosen: 
   try: 
    choice = raw_input(prompt).split()[0].lower() 
   except (EOFError,KeyboardInterrupt): 
    choice = 'q' 
   print '\nYou picked:[%s]' % choice 
   if choice not in 'lqdcr': 
    print 'invalid option,try again' 
   else: 
    chosen = True 

  if choice == 'q':done = True 
  if choice == 'l':olduser(db) 
  if choice == 'd':deluser(db) 
  if choice == 'c':checkuser(db) 
  if choice == 'r':resetuser(db) 

 fu = file('user.ini','w') 
 pickle.dump(db,fu,True) 
 fu.close() 


if __name__ == '__main__': 
 '''''系统有一个用户名为admin 密码为admin的超级用户,请立即修改密码!''' 
 print 'Welcome to User Information Management System!' 
 Initialization('user.ini') 
 Initialization('time.ini') 
 showmenu()

更加多学习资料请关心专项论题《管住体系开荒》。

更加的多读书资料请关怀专项论题《管住连串开荒》。

以上就是本文的全体内容,希望对大家的就学抱有帮衬,也盼望大家多多扶助脚本之家。

上述正是本文的全部内容,希望对咱们的就学抱有帮助,也冀望大家多多扶助脚本之家。

您也许感兴趣的篇章:

  • python完成员工管理种类
  • python用户管理体系的实例疏解
  • Python达成GUI学生新闻保管体系
  • python实现用户管理种类
  • python完成外送食品消息保管连串
  • python完结学生管理连串
  • python版学生管理种类
  • Python学生成绩管理连串简洁版
  • Python达成学校管理体系
  • Python学生音讯保管类别修改版

你恐怕感兴趣的小说:

  • python完结职工管理序列
  • python用户管理体系的实例讲授
  • Python实现GUI学生新闻保管体系
  • python达成外卖消息保管类别
  • python达成学生管理种类
  • python版学生管理类别
  • Python完结学生战表管理体系
  • Python学生战绩管理类别简洁版
  • Python实现学校管理连串
  • Python学生新闻保管连串修改版


相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图