python1

本文介绍了一个简单的员工信息管理系统,包括录入员工姓名与编号的功能,并能够按照姓名或编号进行排序输出。此外,还提供了一个用户登录系统,能够记录用户的登录时间,并在用户再次登录时提醒其最近一次登录的时间。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、人力资源

创建一个简单的雇员姓名和编号的程序,让用户输入一组雇员姓名和编号。你的程序可以提供按照姓名排序输出功能,雇员姓名显示在前面,后面是对应的雇员编号。

附加题:添加一项功能,按照雇员编号的顺序输出数据。

#!/usr/bin/evn python

#coding:utf-8

dict1={}

dict2={}

def add():

         i=0

         count = input("Enter total number of names:")

         while i < count:

                   name=raw_input("please input employee name:")

                   if name=='__":

                           break

                   number=raw_input("please  input a employee number:")

                   dict1[name]=number

                    dict2[number]=name

                    i+=1

          xuanze()

def xuanze():

         print '''

          1.插入数据

          2.按姓名排序

          3.按编号排序

          4.退出'''

          a = raw_input("what do you want to do:")

          if a == "1":

                  add()

          elif a == "2":

                   for key in sorted(dict1):

                             print key,dict1[key]

           elif a == "3":

                   for key in sorted(dict2):

                             print key,dict2[key]

            elif a == "4":

                    quit

             else:

                     print "input error"

                     pass

if_name_=='_main_':

       xuanze()




2、下面的问题和例题7.1中管理名字——密码的键值对数据的程序有关。

(a)修改那个脚本,使它能记录用户上次的登陆日期和时间(用time模块),并与用户密码一起保存起来。程序的界面有要求用户输入用户名和密码的提示。无论户名是否成功登陆,都应有提示,在户名成功登陆后,应更新相应用户的上次登陆时间戳。如果本次登陆与上次登陆在时间上不相差四个小时,则通知该用户:“You already loged in at :<last_login_timestamp>.”

(b)添加一个“管理”菜单,其中有以下两项:(1)删除一个用户 (2)显示系统中所有的用户名字和他们的密码的清单

#!/usr/bin/env python

#coding:utf-8

from time import time,ctime

dic = {}

def user():

         name=raw_input("please input username:")

         if name in dic:

                 passwd=raw_input("please input password:")

                 if passwd == dic.get(name)[0]:

                           print 'Holle,welcome back',name

                           print 'You last login time

at:'ctime(dic[name][1])

                            now=time()

                             timediff=now-dic[name][1]

                             if timediff <= 14400:

                                       print"You already logged within 4 hours!"

                             else:

                                      logintime=time()

                                      dic[name][1]=logintime

                   else:

                            print "password error!"

        else:

                a = raw_input("the name is not exit!do you want to login it:yes/no:")

                if a == "yes":

                        while Ture:

                                    name = raw_input("please input your name:")

                                    if dic.has_key(name):

                                             a = raw_input("User name already exists,please input again:")

                                              continue

                                     else:

                                               break

                          passwd=raw_input("please input password:")

                          logintime=time()

                          dic[name]=[passwd,logintime]

                  if a == "no":

                           user()

            xuanze()

def delete():

           name=raw_input("Please enter the user you want to delete:")

            if name in dic:

                         del dic[name]

              else:

                          print("the name is not exit!please input again:")

                          delete()

               xuanze()

def xuanze():

              print""

              1.登陆界面

              2.删除用户

              3.显示所有用户

              4。退出“”

              a = raw_input("what do you want to do:")

              if a == "1":

                       user()

               elif a == "2":

                        delete()

                elif a == "3":

                         print dic

                         xuanze()

                 elif a == "4":

                         quit

                  else:

                          print "input error"

                          pass

if__name__=='__main__':

       xuanze()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值