2007年01月23日 星期二 14:30
db={} def newuser(): prompt='login desired:' while 1: name=raw_input(prompt) if db.has_key(name): prompt='name taken,try anoter:' continue else: break pwd=raw_input('password:') db[name]=pwd def olduser(): name=raw_input('login:') pwd=raw_input('password') passwd=db.get(name) if passwd==pwd: pass else: print'login incorrect' return print 'welcome back',name def showmenu(): prompt=""" (N)ew User Login (E)xisiting User Login (Q)uit enter ur choice:""" done=0 while not done: chosen=0 while not chosen: try: choice=raw_input(promopt)[0] except (eoferror,keyboardinterrupt): choice='q' print '\nu picked:[%s]'%choice if choice not in 'neq': print 'invalid option,try agian' else: chosen=1 if choice=='q':done=1 if choice=='n':newuser() if choice=='e':olduser() if _name_=='_main_': showmenu() 我在学习PYTHON。刚学到字典,这是一个书上的例子,通过一个虚拟的登陆数据库对用户名和密码进行管理,我把它编好了,存在C:\python24\login.py,我用的 XP操作系统,我在MSDOS下进到c:\python24输入login.py,为什么没什么反映,不是应该出现 N)ew User Login (E)xisiting User Login (Q)uit 吗?请高手指点,谢谢!! -------------- 涓嬩竴閮ㄥ垎 -------------- 一个HTML附件被移除... URL: http://python.cn/pipermail/python-chinese/attachments/20070123/d18a9bff/attachment.html
2007年01月23日 星期二 14:43
你的缩近有问题。 -- I like python! UliPad <>: http://wiki.woodpecker.org.cn/moin/UliPad My Blog: http://www.donews.net/limodou
2007年01月23日 星期二 14:52
你的代码有2个问题: 1. 缩进有问题,程序根本不会启动 2. 程序入口写错了,应该是if __name__ == '__main__': 前后各是两个下划线,你只用了一个。 正确的代码如下: db={} def newuser(): prompt='login desired:' while 1: name=raw_input(prompt) if db.has_key(name): prompt='name taken,try anoter:' continue else: break pwd=raw_input('password:') db[name]=pwd def olduser(): name=raw_input('login:') pwd=raw_input('password') passwd=db.get(name) if passwd==pwd: pass else: print'login incorrect' return print 'welcome back',name def showmenu(): prompt=""" (N)ew User Login (E)xisiting User Login (Q)uit enter ur choice:""" done = 0 while not done: chosen=0 while not chosen: print 'start choosing' try: choice=raw_input(prompt)[0] except (eoferror,keyboardinterrupt): choice='q' print '\nu picked:[%s]'%choice if choice not in 'neq': print 'invalid option,try agian' else: chosen=1 if choice=='q':done=1 if choice=='n':newuser() if choice=='e':olduser() if __name__ =='__main__': showmenu() On 1/23/07, 田径 <jiehama2008在163.com> wrote: > > > > > db={} > def newuser(): > prompt='login desired:' > while 1: > name=raw_input(prompt) > if db.has_key(name): > prompt='name taken,try anoter:' > continue > else: > break > pwd=raw_input('password:') > db[name]=pwd > def olduser(): > name=raw_input('login:') > pwd=raw_input('password') > passwd=db.get(name) > if passwd==pwd: > pass > else: > print'login incorrect' > return > print 'welcome back',name > def showmenu(): > prompt=""" > (N)ew User Login > (E)xisiting User Login > (Q)uit > enter ur choice:""" > done=0 > while not done: > chosen=0 > while not chosen: > try: > choice=raw_input(promopt)[0] > except (eoferror,keyboardinterrupt): > choice='q' > print '\nu picked:[%s]'%choice > if choice not in 'neq': > print 'invalid option,try agian' > else: > chosen=1 > if choice=='q':done=1 > if choice=='n':newuser() > if choice=='e':olduser() > if _name_=='_main_': > showmenu() > > 我在学习PYTHON。刚学到字典,这是一个书上的例子,通过一个虚拟的登陆数据库对用户名和密码进行管理,我把它编好了,存在C:\python24\login.py,我用的 > XP操作系统,我在MSDOS下进到c:\python24输入login.py,为什么没什么反映,不是应该出现 > N)ew User Login > (E)xisiting User Login > (Q)uit > 吗?请高手指点,谢谢!! > > > ------------------------------ > 独家!网易3G免费邮,还赠送280兆网盘 www.126.com <http://www.126.com/> > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -- Best Regards, Archer Ming Zhe Huang -------------- 下一部分 -------------- 一个HTML附件被移除... URL: http://python.cn/pipermail/python-chinese/attachments/20070123/77761a68/attachment-0001.htm
Zeuux © 2025
京ICP备05028076号