码迷,mamicode.com
首页 > 其他好文 > 详细

Pthon学习一(用户登录交互界面)

时间:2016-08-31 15:59:34      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:python

一、作业

 要求:1、要有一个类似登录操作系统的用户登录的交互。

     2、判断用户是否存在。

     3、输入三次密码错误后,退出。

二、流程图

    按照作业要求流程图如下:


技术分享


Python脚本如下:

  1 #!/usr/bin/env python
  2 
  3 
  4 import sys
  5 
  6 user=["liyuanchuan","zhanggang","gaolixu"]
  7 
  8 passwd={‘liyuanchuan‘:‘yuanchuan‘,‘zhanggang‘:‘zhanggang‘,‘liangqing‘:‘liangqing‘}
  9 
 10 
 11 
 12 count=1
 13 while True:
 14     A=raw_input(‘login:‘).strip()
 15     if A in user:
 16         while count <= 3:
 17             B=raw_input(‘passwd:‘).strip()
 18             if B == passwd[A]:
 19                 print "welcome to python world"
 20                 sys.exit()
 21             else:
 22                 if count == 3:
 23                         print "your username is locked,thank you,goodbay!"
 24                         sys.exit()
 25                 print "your passwd incorrect,you have only remain %s,please input again" %(3-count)
 26                 count=count+1
 27                 continue
 28     else:
 29             print "your username is not exits,please input again"
 30             continue




本文出自 “linux世界” 博客,请务必保留此出处http://liyuanchuan8.blog.51cto.com/6060290/1844697

Pthon学习一(用户登录交互界面)

标签:python

原文地址:http://liyuanchuan8.blog.51cto.com/6060290/1844697

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!