欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python 入门(2)字典的使用,伪查询系统

程序员文章站 2022-03-17 15:55:27
...
#coding=utf-8
import sys
user = {'user':'jshand',
        'pass':'123'
        }
userName  = None

#登录系统
def login():
    userName = raw_input("login user:\n")
    if user['user'] == userName:
        checkpassword()
    else:
        print 'user is error!'
        login()

#验证密码
def checkpassword():
    password = raw_input("login password:\n")
    if user['pass'] == password:
        logon()
    else:
        print 'password is error!'
        checkpassword()

		
		
#登录成功后进入查询  
def logon():
    print 'hello %s' % userName
    query()
    
    
dict = {
        'tt'        :'她是一个麻醉医生(*^__^*) 嘻嘻……',
        'jinshan'   :'他是干it的O(∩_∩)O哈哈~',
        'mama'      :'家庭主妇~~~~(>_<)~~~~',
        }   


#查询系统 输入key 显示查询内容		
def query():
    queryKey = raw_input("Pleas input Your key\n")
    if queryKey =='exit' or queryKey =='quite':
         print 'Exit Success ,Bye!'
         sys.exit()
    if queryKey in dict.keys():
             print 'Query thing is %s' %(dict[queryKey])
             query()
    else:
        print 'Query Key is not exists  for key %s' %(queryKey)
        query()


		
#启动系统.....
login()