score = {"a": 1, "c": 3, "b": 3, "e": 1, "d": 2, "g": 2,
"f": 4, "i": 1, "h": 4, "k": 5, "j": 8, "m": 3,
"l": 1, "o": 1, "n": 1, "q": 10, "p": 3, "s": 1,
"r": 1, "u": 1, "t": 1, "w": 4, "v": 4, "y": 4,
"x": 8, "z": 10}
def scrabble_score(word):
count=0
word.lower()
print word
for char in word:
count=count+score[char]
return count
Run Code Online (Sandbox Code Playgroud)
我基本上必须取输入词并根据字典计算其分数.
此修改后的代码将起作用:
def scrabble_score(word):
count=0
word = word.lower() #assign the result of word.lower() to word
Run Code Online (Sandbox Code Playgroud)
word.lower()
返回修改后的单词,它不会修改字符串inplace.字符串在Python中是不可变的..lower()
返回字符串的事实定义如下:
>>> help(str.lower)
Help on method_descriptor:
lower(...)
S.lower() -> string
Return a copy of the string S converted to lowercase.
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
333 次 |
最近记录: |