2017-02-26 44 views
-4

DEF countLetters(计数):我不知道这个Python代码有什么问题,但它说“预计一个缩进块”?

letterList = []

在计数字母: 如果信不在letterList: letterList.append(字母)

返回letterList

词语= open(“/ Users/Sammi/Desktop/Hw3_nanisama/words.txt”,“r”)

print(words)

打印( “文件长度:”,LEN(字))

打印( “一”,LEN(aCount))

打印( “B:”,LEN(bCount))

的emptyList =名单()

+1

读一本Python书... –

+2

[Python期望的缩进块错误]的可能重复(http://stackoverflow.com/questions/12632615/python-expected-an-indented-block-error) – miradulo

+0

Python是[偏移规则](https: //en.wikipedia.org/wiki/Off-side_rule)语言,从而定义带有缩进的代码块。这段代码没有正确缩进。 –

回答

-2

我认为你需要学习Python语法, 基本你必须写为下面的代码:

def countLetters(count): 

    letterList = [] 

    for letter in count: 
     if letter not in letterList: 
      letterList.append(letter) 

    return letterList 

words = open("/Users/Sammi/Desktop/Hw3_nanisama/words.txt", "r") 

print(words) 

print("File length: ", len(words)) 

print("a: ", len(aCount)) 

print("b: ", len(bCount)) 

emptyList = list()