Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 拼字游戏功能不工作(MIT 6.0001 pset 3:)_Python_Function_Dictionary_For Loop - Fatal编程技术网

Python 拼字游戏功能不工作(MIT 6.0001 pset 3:)

Python 拼字游戏功能不工作(MIT 6.0001 pset 3:),python,function,dictionary,for-loop,Python,Function,Dictionary,For Loop,下面的代码没有执行,我不知道为什么。当我尝试运行它时,我得到了“语法错误” SCRABBLE_LETTER_VALUES = { 'a': 1, 'b': 3, 'c': 3, 'd': 2, 'e': 1, 'f': 4, 'g': 2, 'h': 4, 'i': 1, 'j': 8, 'k': 5, 'l': 1, 'm': 3, 'n': 1, 'o': 1, 'p': 3, 'q': 10, 'r': 1, 's': 1, 't': 1, 'u': 1, 'v': 4, 'w': 4,

下面的代码没有执行,我不知道为什么。当我尝试运行它时,我得到了“语法错误”

SCRABBLE_LETTER_VALUES = {
'a': 1, 'b': 3, 'c': 3, 'd': 2, 'e': 1, 'f': 4, 'g': 2,
'h': 4, 'i': 1, 'j': 8, 'k': 5, 'l': 1, 'm': 3, 'n': 1,
'o': 1, 'p': 3, 'q': 10, 'r': 1, 's': 1, 't': 1, 'u': 1,
'v': 4, 'w': 4, 'x': 8, 'y': 4, 'z': 10
}


def get_word_score(word, n):
    char_values = 0
    for char in word:
        char_values += SCRABBLE_LETTER_VALUES[char.lower()]
    if 1 >= (7*len(word) - 3*(n-len(word))):
        print (char_values * 1)
    else:
        print (char_values * (7*len(word) - 3*(n-len(word)))



get_word_score('lazxocijhoaewsfj', 5)

else
中的
print
语句缺少右括号:

def get_word_score(word, n):
    char_values = 0
    for char in word:
        char_values += SCRABBLE_LETTER_VALUES[char.lower()]
    if 1 >= (7*len(word) - 3*(n-len(word))):
        print (char_values * 1)
    else:
        print (char_values * (7*len(word) - 3*(n-len(word)))) # <-- Need another )
def get_word_分数(word,n):
字符值=0
对于word中的字符:
字符值+=拼字字母值[char.lower()]
如果1>=(7*len(单词)-3*(n-len(单词)):
打印(字符值*1)
其他:

打印(char_值*(7*len(word)-3*(n-len(word)))#失败的地方?我忘了在末尾添加括号。如果我加上括号,函数就可以工作了。