亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
最近訪問(wèn)板塊 發(fā)新帖
查看: 5418 | 回復(fù): 6
打印 上一主題 下一主題

書(shū)上的例子,有些不解 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2013-08-15 15:06 |只看該作者 |倒序?yàn)g覽
1 #!/usr/bin/env python
2
Edit By Vheavens
Edit By Vheavens
3 db = {}
4
5 def newuser():
6 prompt = 'login desired: '
7 while True:
8 name = raw_input(prompt)
9 if db.has_key(name):
10 prompt = 'name taken, try another: '
11 continue
12 else:
13 break
14 pwd = raw_input('passwd: ')
15 db[name] = pwd
16
17 def olduser():
18 name = raw_input('login: ')
19 pwd = raw_input('passwd: ')
20 passwd = db.get(name)
21 if passwd == pwd:
22 print 'welcome back', name
23 else:
24 print 'login incorrect'
25
26 def showmenu():
27 prompt = """
28 (N)ew User Login
29 (E)xisting User Login
30 (Q)uit
Example 7.1 Dictionary Example (userpw.py) (continued)
31
32 Enter choice: """
33
34 done = False
35 while not done:
36
37 chosen = False
38 while not chosen:
39 try:
40 choice = raw_input(prompt).strip()[0].lower()
41 except (EOFError, KeyboardInterrupt):
42 choice = 'q'
43 print '\nYou picked: [%s]' % choice
44 if choice not in 'neq':
45 print 'invalid option, try again'
46 else:
47 chosen = True
49 done = True
50 newuser()
51 olduser()
52
53 if __name__ == '__main__':
54 showmenu()


選擇e的時(shí)候 可以直接執(zhí)行olduser()函數(shù)嗎?
書(shū)上給出的是可以執(zhí)行,沒(méi)有看懂,請(qǐng)高手指點(diǎn)一下。

論壇徽章:
13
丑牛
日期:2013-08-16 15:08:22技術(shù)圖書(shū)徽章
日期:2013-11-26 10:13:40雙魚(yú)座
日期:2013-11-08 15:03:26戌狗
日期:2013-11-08 13:52:30技術(shù)圖書(shū)徽章
日期:2013-11-05 14:06:30戌狗
日期:2013-10-31 11:45:42CU十二周年紀(jì)念徽章
日期:2013-10-24 15:41:34天秤座
日期:2013-10-11 14:55:08子鼠
日期:2013-09-26 19:36:35水瓶座
日期:2013-09-26 17:44:56午馬
日期:2013-08-26 10:24:23丑牛
日期:2013-08-19 14:43:22
2 [報(bào)告]
發(fā)表于 2013-08-15 17:16 |只看該作者
這代碼一坨坨的,貼出來(lái)也不把他對(duì)整齊點(diǎn)

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2013-08-15 18:36 |只看該作者
樓主你這代碼真心的難看。

論壇徽章:
4
金牛座
日期:2013-10-11 16:12:50卯兔
日期:2014-07-31 09:17:19辰龍
日期:2014-08-08 09:28:02獅子座
日期:2014-09-14 20:32:05
4 [報(bào)告]
發(fā)表于 2013-08-16 11:44 |只看該作者
這代碼僅僅是難看嗎?
lz難道不知道python的縮進(jìn)代表什么嗎?

論壇徽章:
0
5 [報(bào)告]
發(fā)表于 2013-08-18 14:02 |只看該作者
知道縮進(jìn),這個(gè)是從pdf上復(fù)制過(guò)來(lái)的,沒(méi)有縮進(jìn)的
只是這個(gè)例子和書(shū)上的結(jié)果不同,我已經(jīng)詳細(xì)看了,是缺少了判斷

論壇徽章:
0
6 [報(bào)告]
發(fā)表于 2013-08-18 14:04 |只看該作者
很對(duì)不起大家
#!/usr/bin/env python
db={}

def useradd():
    while True:
        user = raw_input("Enter username:")
        if user in db:
            print "username is exist,please input again"
            continue
        else:
            break
    pwd = raw_input("Enter user passwd:")
    db[user]=pwd
    showmenu()

def olduser():
    username = raw_input("Input username:")
    pwd = raw_input("Input password:")
    if username in db and pwd ==db[username]:
        print 'welcome %s' % username
    else:
        print 'input username or password is wrong'

def showmenu():
    prompt = """
    (N)ew User Login
    (E)xisting User Login
    (Q)uit
    Example 7.1 Dictionary Example (userpw.py) (continued)
    Enter choice: """
    done = False
    while not done:
        chosen = False
        while not chosen:
            try:
                choice = raw_input(prompt).strip()[0].lower()
            except (EOFError, KeyboardInterrupt):
                choice = 'q'
            print '\nYou picked: [%s]' % choice
            if choice not in 'neq':
                print 'invalid option, try again'
            else:
                chosen = True
                done = True
    useradd()
    olduser()
if __name__ == '__main__':
    showmenu()

論壇徽章:
0
7 [報(bào)告]
發(fā)表于 2013-08-18 14:05 |只看該作者
這個(gè)例子是python核心編程里面的
跑起來(lái)和例子的結(jié)果不同的
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過(guò)ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP