码迷,mamicode.com
首页 > 编程语言 > 详细

pythone-2:用户登录并根据条件查询

时间:2015-07-07 19:49:01      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:python

#!/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
                                                        

本文出自 “刘福” 博客,谢绝转载!

pythone-2:用户登录并根据条件查询

标签:python

原文地址:http://liufu1103.blog.51cto.com/9120722/1671701

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