# -*- coding:utf-8 -*-
""" 字典作为数据库模拟用户登录"""
db={}
def newuser():
while True:
name=raw_input('login desired:').strip()
if db.has_key(name):
print 'name taken:%d,try other'%name
continue
else:
break
pwd=raw_input('password:').strip()
db[name]=pwd
def olduser():
while True:
name=raw_input('login:').strip()
pwd=raw_input('password:').strip()
if db[name]==pwd:
print 'welcome back:%s'%name
break
else:
print 'name or pwd invalid,try again'
continue
def showmenu():
prompt='''
(N)ew user login desired
(E)xisting user login
(Q)uit
Entry your choice:
'''
while True:
choice=raw_input(prompt).strip().lower()
if choice not in 'neq':
print 'input invalid char,please entry again'
continue
elif choice=='n':
newuser()
print 'login desired success'
break
elif choice=='e':
olduser()
break
else:
break
if __name__=='__main__':
showmenu()