Bug 2: Capital Letters چالش 4 از جلسهی 47، متوسط
دستیار «Where do Sand Foxes sleep?» را جواب نمیدهد ولی «where do sand foxes sleep?» را میدهد. words را درست کن: حرفها باید کوچک شوند و علامتهای .,?! فاصله شوند. خروجی درست:['foxes', 'sand', 'sleep', 'where']32
STOP = {"the", "a", "an", "is", "of", "in", "on", "and", "what", "how", "do", "does", "it", "at", "to", "many"}
def words(text):
clean = ""
for ch in text:
if ch in ".,?!":
clean += " "
else:
clean += ch
result = set()
for w in clean.split():
if w not in STOP:
result.add(w)
return result
def score(question, chunk):
return len(words(question) & words(chunk))
# ---- test (do not change) ----
print(sorted(words("Where do Sand Foxes sleep?")))
print(score("Where do Sand Foxes sleep?", "The sand foxes of Nilu sleep in the day."))
print(score("WHEN does sprout water the beds", "Sprout waters the beds at 7."))
راهنما و جواب این چالش · برگشت به درس جلسهی 47: پروژهی نهایی ۲: ساختن و آزمودن · چالش بعدی: Fixed or Broken?
بیشتر بخوان: تابع در پایتون: آموزش def، پارامتر و return با مثال