Score a Sentence چالش 3 از جلسهی 33، متوسط
تابع score(sentence) را کامل کن: برای هر کلمه WEIGHTS.get(word, 0) را به total اضافه کن. خروجی:4 great fun-3 so boring and slow-1 i hate this but i love the music
WEIGHTS = {"great": 2, "fun": 2, "love": 2, "nice": 1, "cool": 1, "kind": 2,
"boring": -2, "bad": -1, "stupid": -3, "ugly": -2, "hate": -3, "slow": -1}
def score(sentence):
total = 0
return total
for s in ["great fun", "so boring and slow", "i hate this but i love the music"]:
print(score(s), s)
راهنما و جواب این چالش · برگشت به درس جلسهی 33: خوب یا بد؟ · چالش بعدی: Kind, Unkind or Can't Tell
بیشتر بخوان: تابع در پایتون: آموزش def، پارامتر و return با مثال