Kodewick
开始学 →
入门←→0 / 80

书架标签

#021入门字符串约 3 分钟

旧书店要给书架做标签。书名有的全是大写,有的前后多了空格。写 shelf_label(book):去掉两头的空格,再让每个词首字母大写、其余小写。空字符串返回空字符串。

示例
shelf_label(" the little prince ")→'The Little Prince'
shelf_label("MOBY DICK")→'Moby Dick'
main.py
def shelf_label(book):
    # 在这里写:先 strip() 再 title(),把结果返回
    return book
Ctrl + Enter 也能运行
结果

写好了先点「运行」试试示例,没问题再点「提交」。