第六次高级编程高级作业

6-2 喜欢的数字

favourite_number ={
    'Bob' : '12',
    'Tom' :  '6',
    'Lucy':  '7',
    'Coco':  '9',
    'Pat' :  '22'
}
my_friends = ['Bob','Tom','Lucy','Coco','Pat'];
for my_friend in my_friends:
    print(my_friend + " 's favourite number is "+ favourite_number[my_friend] );

6-5 河流

river_country = {
    'nile': 'egypt',
    'Chao Phraya River' : 'Thailand ',
    'Mississippi River' : 'america'
}
for river , country in river_country.items():
    print(river.title() + " run through the " + country.title());
for river  in river_country.keys():
    print(river.title());
for country  in river_country.values():
    print(country.title());

6-8 宠物

pets = [];
Wangwang = {
    'Type' : 'dog',
    'Owner': 'Tom'
}
pets.append(Wangwang);

Miaomiao = {
    'Type' : 'cat',
    'Owner' : 'Pat'
}
pets.append(Miaomiao);

Huhu = {
    'Type' : 'Panda',
    'Owner' : 'dalao'
}
pets.append(Huhu);

for pet in pets:
    for key in pet.keys():
        print(key +" : " + pet[key]);

6-10 喜欢的数字

favourite_number ={
    'Bob' : ['12','11','9'],
    'Tom' :  ['6'],
    'Lucy':  ['3','2','10'],
    'Coco':  ['9','8','7'],
    'Pat' :  ['22']
}
for person in favourite_number.keys():
    for number in favourite_number[person]:
        print(person + " likes "+ number);

猜你喜欢

转载自blog.csdn.net/riddlexyz/article/details/79674722