python作业

2023-01-31 02:01:17 python 作业

创建以用户登录程序:保存用户的用户名与密码

 新建用户时,判断用户是否已经存在,若存在则报错;

 登录系统是,确保用户名存在于系统中,密码正确,有三次机会,超过三次报错冷却

 

#!/usr/bin/env python

# coding:utf-8

 

name = ['root','linux']

passwd = ['redhat']

def select():

  create=raw_input("输入你要建立的用户名:")

  if create in name:

     print "用户已存在"

  else:

    name.append(create)

    print '用户建立成功'

def denglu():

  for i in (1,6):

    name1 = raw_input('请输入帐号:')

    passwd1 = raw_input('输入密码:')

    if (name1 in name and passwd1 in passwd):

        print 'welcome to user manager system'

        exit(0)

    else:

           print '用户名或密码错误'

  print ('密码错误三次,冷却时间三分钟')

def showmenu():

      pro = """

                    欢迎使用xxx登陆器

        

        

新建用户(S/s)

登陆系统(D/d)

Enter choice:"""

      while True:

          choice = raw_input(pro).lower()

          if choice == 's':

              select()

          elif choice == 'd':

              denglu()

          else:

              print "input s/d"

showmenu()


相关文章