爲什麼數字和總長度仍然是0?我究竟做錯了什麼。它應該到期行聲明已經改爲線路這個程序有什麼問題?爲什麼數字和totalLength 0?
def cleanedup(s):
alphabet= 'abcdefghijklmnopqrstuvwxyz'
cleantext = ''
for character in s.lower():
if character in alphabet:
cleantext += character
else:
cleantext = ' '
return cleantext
import shelve
shelf = shelve.open('books')
lines = shelf['Pride and Prejudice']
shelf.close()
number = 0
totalLength = 0
for line in lines:
for word in cleanedup(line).split():
number += 1
totalLength += len(word)
print(totalLength, number)
什麼是「線條」和「cleanedup」?如果你沒有向我們展示所有的代碼,我們應該如何知道你的代碼在做什麼? – jwodder
什麼是'線條'和'cleanedup'?請創建一個[最小測試用例](http://stackoverflow.com/help/mcve)。 –
我編輯了它..... –