第六章课后作业

Chapter Six

6-1 人

james = {
    'first_name': "James",
    'last_name' : "Brown",
    'age' : 23,
    'live_city' : "Hong Kong"
}
print("First name:\t" + james['first_name'])
print("Last name:\t" + james['last_name'])
print("Age:\t\t" + str(james['age']))
print("Live city:\t" + james['live_city'])

6-2 喜欢的数字

favorite_nums = {
    'Yamato': 23,
    "Fubuki": 35,
    "Sakura": 10086,
    "Shimakaze": 2333,
    "Saratoga": 666
}
for name, num in favorite_nums.items():
    print(name + "'s favorite number is " + str(num))

6-3 词汇表

vocabulary_table = {
    'python': "A popular programing language",
    'list': "A kind of structure which linked data with index",
    'ergodic': "Travel all stored values in a structure in order",
    'tuple': "A kind of structure like a unmodified list",
    'output': "an amount of something produced by a person, machine, factory, country, etc"
}
print("python:\t" + vocabulary_table['python'])
print("list:\t" + vocabulary_table['list'])
print("ergodic:\t" + vocabulary_table['ergodic'])
print("tuple:\t" + vocabulary_table['tuple'])
print("output:\t" + vocabulary_table['output'])

6-4 词汇表2

vocabulary_table = {
    'python': "A popular programing language",
    'list': "A kind of structure which linked data with index",
    'ergodic': "Travel all stored values in a structure in order",
    'tuple': "A kind of structure like a unmodified list",
    'output': "an amount of something produced by a person, machine, factory, country, etc"
}
for vocabulary, explanation in vocabulary_table.items():
    print(vocabulary + ":\t" + explanation)

6-5 河流

dict_river = {
    'nile': 'Egypt',
    'amazon': 'Colombia',
    'changjiang': 'China'
}
for river, country in dict_river.items():
    print("The " + river + " river runs through " + country)
for river in dict_river.keys():
    print(river)
for country in dict_river.values():
    print(country)

6-6 调查

research_list = ["Zhang San", "Li Si", "Wang Wu", "Zhou Liu"]
research_result = {
    "Zhang San": 13,
    "Wang Wu": 25,
    "Zhou Liu": 33
}
for name in research_list:
    if name in research_result.keys():
        print(name + ", thank you for joining our research.")
    else:
        print(name + ", would you like to join our research?")

6-7 人

james = {
    'first_name': "James",
    'last_name' : "Brown",
    'age': 23,
    'live_city' : "Hong Kong"
}
tom = {
    'first_name': "Tom",
    'last_name': "Smith",
    'age': 19,
    'lived_city': "Guangzhou"
}
jack = {
    'first_name': "jack",
    'last_name': "Green",
    'age': 25,
    'lived_city': "Shanghai"
}
people_list = [james, jack, tom]
for people in people_list:
    print("First name:\t" + james['first_name'])
    print("Last name:\t" + james['last_name'])
    print("Age:\t\t" + str(james['age']))
    print("Live city:\t" + james['live_city'])
    print()

6-8 宠物

dabai = {
    'name': "Dabai",
    'type': "cat",
    'owner': "Zhang San"
}
erhuang = {
    'name': "Erhuang",
    'type': "dog",
    'owner': "Li Si"
}
ahua = {
    'name': "Ahua",
    'type': "bird",
    'owner': "Wang Wu"
}
pets = [dabai, erhuang, ahua]
for pet in pets:
    print("Name:\t" + pet['name'] + "\nType:\t" + pet['type'] + "\nOwner:\t" + pet['owner'] + "\n")

6-9 喜欢的地方

favorite_places = {
    'Zhang San': ['Shanghai', 'Beijing', 'New York'],
    'Li Si': ['Chongqing', 'Guangzhou'],
    'Wang Wu': ['Singapo', 'Tokyo']
}
for people, places in favorite_places.items():
    print("Name:\t" + people)
    print("Favorite Place:\t")
    for place in places:
        print("\t" + place)
    print()

6-10 喜欢的数字

favorite_nums = {
    'Yamato': [23, 35],
    "Fubuki": [6, 17],
    "Sakura": [1024],
    "Shimakaze": [2333, 666, 888],
    "Saratoga": [9420]
}
for name, nums in favorite_nums.items():
    if len(nums) > 1:
        print(name + "'s favorite numbers are:")
    else:
        print(name + "'s favorite number is:")
    for num in nums:
        print("\t" + str(num))

6-11 城市

cities = {
    'Shanghai': {
        'country': 'China',
        'population': 2.420e7,
        'fact': 'Shanghai is a big city'
    },
    'New York': {
        'country': 'USA',
        'population': 8.51e6,
        'fact': 'New York belongs to USA'
    },
    'Beijing':{
        'country': 'China',
        'population': 2.173e7,
        'fact': "Beijing is the capital of China"
    }
}
for city, info in cities.items():
    print(city)
    print('Country:\t' + info['country'])
    print('Population:\t' + str(info['population']))
    print('Describe:\t' + info['fact'])
    print()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值