
452
|
附录
D
9.
将
surprise
中最后一个列表项改为小写,然后将其逆置,再大写首字母。
>>> surprise[-1] = surprise[-1].lower()
>>> surprise[-1] = surprise[-1][::-1]
>>> surprise[-1].capitalize()
'Oprah'
10.
使用列表推导式创建包含在
range(10)
之内的所有偶数的列表
even
。
>>> even = [number for number in range(10) if number % 2 == 0]
>>> even
[0, 2, 4, 6, 8]
11.
创建一个跳绳押韵制作器。你将打印一系列双行韵文。从以下程序片段开始。
start1 = ["fee", "fie", "foe"]
rhymes = [
("flop", "get a mop"),
("fope", "turn the rope"),
("fa", "get your ma"),
("fudge", "call the judge"),
("fat", "pet the cat"),
("fog", "walk the dog"),
("fun", "say we're done"),
]
start2 = "Someone better"
对于
rhymes
中的每个字符串对
(first, second)
:
就第一行:
•
打印
start1
中的各个字符串,将首字母大写,随后跟上一个惊叹号和空格; ...