【第三周】第六章全部习题

 6-1人
people = { 'first_name':'Lucy', 'last_name': 'Zheng' , 'age': 20 , 'city': 'Guangzhou'}
print (people)



6-2喜欢的数字
num = {'Lucy': 17 , 'Peppa': 2 , 'George': 4 , 'LittlePig': 7}
print (num)



6-3 词汇表
vo = {
    'del': 'delete sth',
    '.lower()' : 'the lower case of the string',
    '.upper()' : 'the upper case of the string',
    'if' : 'to judge',
    'len' : 'the length of sth'
    }
for key in vo.keys():
    print(key+' : '+vo[key])



6-4词汇表2
vo = {
    'del': 'delete sth',
    '.lower()' : 'the lower case of the string',
    '.upper()' : 'the upper case of the string',
    'if' : 'to judge',
    'len' : 'the length of sth',
    'print': 'print sth on the screen',
    '.key()': 'find the keys of the vocabulary',
    '.items' : 'find the items of the vocabulary',
    '.values()' : 'find the values of the vocabulary',
    'else' : 'to  judge'
    }
for key,value in vo.items():
    print(key+' : '+value)



6-5河流
river = {
    'nile' : 'Egypt',
    'Times' : 'England',
    'The Changjiang river' : 'China'
    }
for key,value in river.items():
    print('The '+ key.title() + ' runs through ' + value)
for key in river.keys():
    print(key)
for value in river.values():
    print(value)



6-6调查

people = ['Peppa','George','Bob']
serve = {'Bob':'Have done'}
for peo in people:
    if peo in serve.keys():
        print(peo + ',thank you for attending our serving.')
    else:
        print(peo + ',please attend our serving.')


6-7人
people1 = { 'first_name':'Lucy', 'last_name': 'Zheng' , 'age': 20 , 'city': 'Guangzhou'}
people2 = { 'first_name':'Jair', 'last_name': 'Zhu' , 'age': 20 , 'city': 'Guangzhou'}
people3 = { 'first_name':'David', 'last_name': 'Li' , 'age': 19 , 'city': 'Guangzhou'}
people = [people1,people2,people3]
for pe in people:
    print(pe)




6-8宠物
Candy = {'type': 'cat' , 'owner' : 'Bob'}
Peppa = {'type': 'pig' , 'owner' : 'Kevin'}
Suxy = {'type': 'sheep' , 'owner' : 'Stuart'}
pets = [Candy,Peppa,Suxy]
for pet in pets:
    print(pet)



6-9喜欢的地方
favourite_places = {
    'Bob' : ['Beijing','Shanghai','Guangzhou'],
    'Kevin' : ['Chongqing','Xian','Harbin'],
    'Stuart' : ['Chengdu' ,'Guilin' ,'Xiamen']
}
for key,value in favourite_places.items():
    print (key + ' ' , value)



6-10喜欢的数字
num = {
    'Lucy': [17,18,19], 
    'Peppa': [2,3,4], 
    'George': [4,5,6], 
    'LittlePig': [7,8,9]
    }
for key,value in num.items():
    print(key,value)



6-11城市
cities = {
    'Beijing': { 'Country':'China','population':21730000,'fact':'the center of politics'},
    'Shanghai': { 'Country':'China','population':24200000,'fact':'the center of economy'},
    'Guangzhou' : {'Country':'China','population':14490000,'fact':'the center of exportation'},
}
for key,value in cities.items():
    print (key,' ',value)


6-12扩展
favourite_languages = {
    'jen': 'python',
    'sarah': 'c',
    'edward': 'ruby',
    'phil': 'python',
    }
favourite_languages['Bob'] = 'php'
for key,value in favourite_languages.items():
    print (key,' ',value)




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值