您的位置:首页 > 编程语言 > Python开发

Python小作业一(用户登录交互界面)

2016-08-31 12:21 211 查看
一、作业
要求: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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Python