简单

单词小工坊

帮妹妹完成英语词汇作业!你将用 Python 的字符串操作来添加前缀、拼接词组、移除后缀、以及从句子中提取单词并变形。

1. add_prefix_un — 加 un 前缀

创建 add_prefix_un(word) 函数,接收一个参数:

  1. word — 一个单词(字符串)

返回在前面加上 "un" 前缀的结果。

>>> add_prefix_un("happy")
'unhappy'
>>> add_prefix_un("manageable")
'unmanageable'

2. make_word_groups — 用前缀拼词组

创建 make_word_groups(vocab_words) 函数,接收一个参数:

  1. vocab_words — 单词列表,第一个元素是前缀,后面的元素是词根

" :: " 作为分隔符连接所有单词。提示:用 .join() 方法,不需要循环

>>> make_word_groups(['en', 'close', 'joy', 'lighten'])
'en :: enclose :: enjoy :: enlighten'

3. remove_suffix_ness — 去掉 ness 后缀

创建 remove_suffix_ness(word) 函数,接收一个参数:

  1. word — 以 ness 结尾的单词

去掉 ness 后缀。如果去掉后最后一个字母是 i,把它改成 y

>>> remove_suffix_ness('heaviness')
'heavy'
>>> remove_suffix_ness('sadness')
'sad'

4. adjective_to_verb — 形容词变动词

创建 adjective_to_verb(sentence, index) 函数,接收两个参数:

  1. sentence — 一个英文句子
  2. index — 目标单词在句子中的位置

.split() 拆出单词,取 index 位置的形容词,去掉末尾标点,再加 "en" 变成动词。

>>> adjective_to_verb('It got dark as the sun set.', 2)
'darken'

你将学到的知识

概念对应函数
字符串拼接 +add_prefix_un
.join() 连接列表make_word_groups
字符串切片 [:-4]remove_suffix_ness
.split() + 索引adjective_to_verb
负数索引 [-1]3, 4
Ln 1, Col 1
测试结果
点击「测试」运行用例,通过后点击「提交」