#!/usr/bin/env python
#定义一个退出变量
EXIT="exit"
#最大登录次数初值
num=1
#开始
while num < 4:
num = num + 1
#让用户输入登录名:lf
user = raw_input("Login name:")
#判断用户是否合法
if user == "lf":
#输入用户密码并判断其是否合法
password =raw_input("password:")
p = "123456"
while password != p :
password = raw_input("please pass try again:")
else:
#成功登录
print "Welcome"
while True:
f = 0
#输入查询条件
user_input = raw_input('Please input you select name:')
#读取用户文件
my_file = file('myfile.txt')
#判断,如果输入为空或者空格,给出错误提示并开始下一次循环
if len(user_input) == 0 or " " in user_input:
print "bu he fa "
continue
while True:
line = my_file.readline()
if len(line) == 0:
break
if user_input in line:
print "%s" % line,
f = 1
if user_input == EXIT:
exit(1)
else:
pass
if f == 0:
print "Could not find "
else:
print "Sorry ,user %s not found" %user
本文出自 “刘福” 博客,谢绝转载!