一、需求
编写一个用于验证员工登录并采集员工信息的接口
员工尝试登录次数为3次,超过三次被锁定
员工输入个人信息并存档,可重复输入两次,若两次输入个人信息错误,则程序结束
二、代码
#!/usr/bin/env python #_*_coding:utf-8_*_ import sys from imaplib import Continuation username = ‘mangguo‘ password = ‘json‘ try_time = 0 while try_time < 3: username_input = raw_input(‘input your username:‘) if username_input == username: password_input = raw_input(‘input your password:‘) if password_input == password: print ‘Welcome,%s‘,username try_time+=1 break else: print ‘password ERROR!‘ try_time+=1 continue else: print ‘username ERROR!‘ try_time+=1 continue else: print ‘login fail!‘ sys.exit() sex = raw_input(‘input your sex:‘) age = int(raw_input(‘input your age:‘)) job = raw_input(‘input your job:‘) print ‘your infornation:‘ print (‘username:%s,sex:%s,job:%s,age:%d‘)%(username,sex,job,age) choice = raw_input(‘the information is right?(Y/N)‘) yes = ‘Y‘ no = ‘N‘ while choice == yes: print ‘finished!‘ sys.exit() else: sex = raw_input(‘input your sex again:‘) age = int(raw_input(‘input your age again:‘)) job = raw_input(‘input your job again:‘) choice_1 = raw_input(‘the information is right?(Y/N)‘) if choice_1 == yes: print ‘finished!‘ sys.exit() else: print ‘input information ERROR!‘ sys.exit()
本文出自 “mangguo” 博客,请务必保留此出处http://mangguostudy.blog.51cto.com/5643869/1734002
原文地址:http://mangguostudy.blog.51cto.com/5643869/1734002