我必須編寫一個函數,該函數應該返回bool值True如果您只能使用myLetters中的字母拼出myWord,並且返回bool值如果不能。
要做到這一點,我需要我的letterPoints字典是:CanWeMakeIt函數python,它不會返回任何東西
global letterPoints
letterPoints = {"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 canWeMakeIt(myWord, myLetters):
canMake = True
letterPoints= list(myLetters)
length=len(myWord)
for i in range(length):
i=i+1
letter=myWord[i]
if letter not in letterPoints:
canMake = False
else:
letterPoints.remove(letter)
return canMake
不正確的做法,你沒有叫它,什麼樣的返回 –
,我該如何去做呢? – hackintosjdn
你只能使用字典密鑰字母的數值個數嗎? –