高级编程技术第六次作业

第六章 字典

6-1 人

personal_information = {
    "first_name": "David",
    "last_name": "Blade",
    "age": 20,
    "city": "NewYork"
}
print (personal_information)

6-2 喜欢的数字

favourite_numbers = {
    "Alice": 1,
    "Bob": 2,
    "Cindy": 3,
    "David": 4,
    "Frank": 5
}
print (favourite_numbers)

6-3 词汇表

Words = {
    "int": "an int number",
    "float": "a float number",
    "double": "a double number",
    "for": "a loop's identifier",
    "while": "a loop's identifier"
}
for word in Words.keys():
    print (word + ": " + Words[word])

6-4 词汇表2

Words = {
    "int": "an int number",
    "float": "a float number",
    "double": "a double number",
    "for": "a loop's identifier",
    "while": "a loop's identifier"
}
for word, value in Words.items():
    print (word + ": " + value)

6-5 河流

Rivers = {
    "nile": "egypt",
    "changjiang": "china",
    "huanghe": "china"
}
for river, country in Rivers.items():
    print ("The " + river + " runs through " + country)
for river in Rivers.keys():
    print (river)
for country in Rivers.values():
    print (country)

6-6 调查

People = ["Alice", "Bob", "Cindy", "David", "Frank", "Eric"]
favorite_languages = {
    "jen": "python",
    "sarah": "c",
    "edward": "ruby",
    "Cindy": "python"
}
for name in favorite_languages.keys():
    if name in People:
        print (name + ", Thank you for investigation!")
    else:
        print (name + ", We sincerely invite you to our investigation!")

6-10 喜欢的数字

favourite_numbers = {
    "Alice": [1, 2, 3],
    "Bob": [2, 3, 4],
    "Cindy": [4, 5, 6],
    "David": [1, 7, 5],
    "Frank": [1]
}
print ("The students and their favourite numbers")
for name, numbers in favourite_numbers.items():
    print (name + "'s favourite numbers are ", end="")
    for number in numbers:
        print (str(number) + " ", end="")
    print ("")

6-11 城市

Cities = {
    "Shenzhen": {"country": "China", "continent": "Asia"},
    "Guangzhou": {"country": "China", "continent": "Asia"},
    "Xianggang": {"country": "China", "continent": "Asia"},
    "Moscow": {"country": "Russia", "continent": "Asia"}
}
for city, information in Cities.items():
    print (city + "'s information: ", end="")
    for country, continent in Cities[city].items():
        print (country + ": "+ continent + " ", end="")
    print ("")
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值