3.21作业

6-6 调查

favorite_language = {
'jen' : 'Python',
'sarah' : 'c',
'edward' : 'ruby',
'phil' : 'python',
'bill' : 'cpp'
}
people_to_be_polled = ('edward', 'phil', 'steve', 'harry')

for person in people_to_be_polled:
if person in favorite_language.keys():
print(person.title() + ", thank you for your participation.")
else:
print(person.title() + ", I invite you to join the poll.")


6-7 人

person1 = {
'first name' : 'first1',
'last name' : 'last1',
'age' : '20',
'city' : 'city1'
}
person2 = {
'first name' : 'first2',
'last name' : 'last2',
'age' : '40',
'city' : 'city2'
}
person3 = {
'first name' : 'first3',
'last name' : 'last3',
'age' : '60',
'city' : 'city3'
}

people = [person1, person2, person3]
for person in people:
for key, value in person.items():
print(key.title() + ": " + value.title())
print()

6-8 宠物

pet1 = {
'kind' : 'dog',
'owner' : 'dog man'
}
pet2 = {
'kind' : 'cat',
'owner' : 'cat man'
}
pet3 = {
'kind' : 'pig',
'owner' : 'pig man'
}
pet4 = {
'kind' : 'turtle',
'owner' : 'turtle man'
}

pets = [pet1, pet2, pet3, pet4]
for pet in pets:
for key, value in pet.items():
print(key.title() + ": " + value.title())
print()


6-11 城市

cities = {
'beijing' : {
'country' : 'China',
'population' : '21 million',
'fact' : 'capital of China'
},
'guangzhou' : {
'country' : 'China',
'population' : '14 million',
'fact' : 'capital of Guangdong'
},
'shanghai' : {
'country' : 'China',
'population' : '24 million',
'fact' : 'the most prosperous city in China'
}
}

for city, info in cities.items():
print(city.title())
for key, value in info.items():
print(key + ": ", value)
print()


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值