Question
教材中课后的练习,6-1到6-12,选一些写到你的博客上
Answer
'''''
SYSU - [专选]高级编程技术 - Week3, Lecture2 HW
by Duan
2018.03.22
'''
'''
6-1 人
'''
info = {'first_name': 'Ying', 'last_name': 'Jiang', 'age': 37,
'city' : 'Guangzhou'}
print(info['first_name'], info['last_name'], 'is', str(info['age']) +
'ys old', 'now and live in', info['city'] + '.')
'''
6-2 喜欢的数字
'''
favorite_num = {'Zhang San': 0, 'Li Si': 1, 'Wang wu': 2,
'Cao Cao': 3, 'Lv Bu': 4}
for key, value in favorite_num.items():
print(key, "'s favorite number is\t", str(value))
'''
6-5 河流
'''
river = {'nile': 'egypt', 'amazon river': 'Brazil',
'the changjiang river': 'china'}
for river, nation in river.items():
print('The', river.title(), 'runs through', nation.title())
'''
6-7 人
'''
people = [
{'first_name': 'Ying', 'last_name': 'Jiang', 'city': 'Guangzhou'},
{'first_name': 'Xueyi', 'last_name': 'Duan', 'city': 'Xiangyang'},
{'first_name': 'Min', 'last_name': 'Huang', 'city': 'Wuhan'},
]
for person in people:
print(person['first_name'].title(), person['last_name'].title(),
'now live in', person['city'] + '.')
'''
6-8 宠物
'''
pets = [
{
'name': 'Zhima',
'species': 'cat',
'host': 'Xueyi Duan'
},
{
'name': 'Pidan',
'species': 'cat',
'host': 'Yuerong Ding'
},
]
for pet in pets:
print(pet['name'], 'is a', pet['species'], 'whose host is',
pet['host'] + '.')