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

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

Chinaunix

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

剛學(xué)python,實(shí)驗(yàn)書上的2個(gè)小程序遇到的問(wèn)題 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2010-09-16 14:10 |只看該作者 |倒序?yàn)g覽
第一個(gè):  if 語(yǔ)句,完全按照書上的書寫

#!/usr/bin/python
# Filename: if.py

number = 23
guess = int(input('Enter an integer : '))

if guess == number:
    print('Congratulations, you guessed it.') # New block statrs here
        print('(but you do not win any prizes!)') # New block ends here
elif guess < number:
    print('No, it is a little higher than that') # Another block
        # You can do whatever you want in a block ...
else:
    print('No, it is a little lower than that')
        # You must have guess > number to reach here
print('Done')

執(zhí)行后報(bào)錯(cuò):

root@ubuntu:~$ python if
  File "if", line 9
    print('(but you do not win any prizes!)') # New block ends here
    ^
IndentationError: unexpected indent


第二個(gè): while語(yǔ)句
#!/usr/bin/python
# Filename while.py

number == 23
running = Ture

while running:
    guess = int(input("Enter a integer: '))
       
        if guess == number:
            print('Congratulations, you guessed it.')
                running = False #thi cause the wile loop to stop
        elif guess < number:
            print('No, it is a little higher than that.')
else:
    print('The while loop is over.')
        # Do anything else you want to do here
print('Done')

執(zhí)行后報(bào)錯(cuò):
root@ubuntu:~$ python while
  File "while", line 8
    guess = int(input("Enter a integer: '))
                                          ^
SyntaxError: EOL while scanning string literal


請(qǐng)各位高人指點(diǎn)。 多謝!

論壇徽章:
2
青銅圣斗士
日期:2015-11-26 06:15:59數(shù)據(jù)庫(kù)技術(shù)版塊每日發(fā)帖之星
日期:2016-07-24 06:20:00
2 [報(bào)告]
發(fā)表于 2010-09-16 16:24 |只看該作者
python縮進(jìn)敏感, 所以

  1. if guess == number:
  2.     print('Congratulations, you guessed it.') # New block statrs here
  3.         print('(but you do not win any prizes!)') # New block ends here
復(fù)制代碼
改為:

  1. if guess == number:
  2.     print('Congratulations, you guessed it.') # New block statrs here
  3.     print('(but you do not win any prizes!)') # New block ends here
復(fù)制代碼
第2個(gè): EOL(end of line) while scanning string literal
掃描string literal時(shí)遇見(jiàn)了行結(jié)束。

string literal的delimiter沒(méi)有匹配:
int(input("Enter a integer: '))

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2010-09-16 17:37 |只看該作者
沒(méi)看也樓上兩個(gè)有啥區(qū)別

論壇徽章:
0
4 [報(bào)告]
發(fā)表于 2010-09-16 20:32 |只看該作者
本帖最后由 a515200 于 2010-09-18 00:29 編輯

~~~~~~~~~~~~~~~

論壇徽章:
0
5 [報(bào)告]
發(fā)表于 2010-09-17 09:35 |只看該作者
input() 可以輸入字符串

論壇徽章:
0
6 [報(bào)告]
發(fā)表于 2010-09-18 14:55 |只看該作者
第一個(gè),二樓說(shuō)對(duì)了,不過(guò),第二個(gè),可不只這個(gè)問(wèn)題。看下面:
  1. #!/usr/bin/python
  2. # Filename while.py

  3. number = 23
  4. running = True

  5. while running:
  6.     guess = int(input("Enter a integer: "))
  7.     if guess == number:
  8.         print('Congratulations, you guessed it.')
  9.         running = False #thi cause the wile loop to stop
  10.     elif guess < number:
  11.         print('No, it is a little higher than that.')
  12. else:
  13.     print('The while loop is over.')
  14.         # Do anything else you want to do here
  15. print('Done')
復(fù)制代碼

論壇徽章:
0
7 [報(bào)告]
發(fā)表于 2010-09-18 14:57 |只看該作者
你的 number 不應(yīng)該是 == 23,running 是True,不是Ture,還有注意縮進(jìn)和單雙引號(hào)對(duì)應(yīng)。

論壇徽章:
0
8 [報(bào)告]
發(fā)表于 2010-09-19 13:00 |只看該作者
我學(xué)習(xí)python的最大感觸就是不要用tab鍵縮進(jìn)哦,去python社區(qū)看下“八榮八恥”吧!

論壇徽章:
0
9 [報(bào)告]
發(fā)表于 2010-09-20 17:02 |只看該作者
回復(fù) 2# OwnWaterloo


    感謝指點(diǎn)!明白啦!

論壇徽章:
0
10 [報(bào)告]
發(fā)表于 2010-09-20 17:17 |只看該作者
你的 number 不應(yīng)該是 == 23,running 是True,不是Ture,還有注意縮進(jìn)和單雙引號(hào)對(duì)應(yīng)。
icykiss 發(fā)表于 2010-09-18 14:57



    非常感謝你的解答,我已經(jīng)改正了縮進(jìn)和拼寫,F(xiàn)在遇到一個(gè)新的問(wèn)題。

Traceback (most recent call last):
  File "while", line 4, in <module>
    number == 23
NameError: name 'number' is not defined


我要在number前定義number為什么類型嗎? 書上為什么沒(méi)寫呀?
您需要登錄后才可以回帖 登錄 | 注冊(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