Python编程之入门到实践 第六章习题代码

6.2习题代码

# 6-1 人
information = {
    'first_name': 'li',
    'last_name': 'jake',
    'age': '18',
    'city': 'guangzhou'
}
print(information['first_name'])
print(information['last_name'])
print(information['age'])
print(information['city'])
print()

# 6-2 喜欢的数字
like_nums = {
    "alex": 3,
    "jake": 2,
    "yi": 6,
    "wang": 5,
    "he": 8,
}
for name,value in like_nums.items():
    print(name + " like the numbers is " + str(value))
print()

# 6-3 词汇表
words = {
    "len": "total the list length",
    "title": "can express the world",
    "max": "get the number max",
    "min": "get the number min",
    "sort": "arrange the order"
}
for word, explain in words.items():
    print(word + " : " + explain + "\n")

6.3习题代码

# 6-5 河流
rivers = {
    "niuniu": "China",
    "lulu": "Japan",
    "nile": "Europe",
}
for river, country in rivers.items():
    print("The "+river.upper()+" run throngh " + country.upper())
print()

for river in rivers.keys():
    print(river)
print()

for country in rivers.values():
    print(country)
print()

# 6-6 调查
list = ["jake", "herry", "bob", "niuma", "zip"]
name_information = {
    "jake": "c",
    "bob": "python",
    "niuma": "java"
}
for name in list:
    if name in name_information.keys():
        print(name + " Thank you can join the survey\n")
    else:
        print(name + " I think you can join the survey\n")

6.4习题代码

#6-7人
person1 = {
    "name": "jake",
    "age": 18,
    "sex": "man"
}
person2 = {
    "name": "judy",
    "age": 18,
    "sex": "man"
}
person3 = {
    "name": "bob",
    "age": 18,
    "sex": "man"
}
people = [person1, person2, person3]
for i in people:
    print(i)

#6-8 宠物
pet1 = {'owner': "bob", 'type': "dog"}
pet2 = {'owner': "alex", 'type': "cat"}
pet3 = {'owner': "jake", 'type': "pig"}
pets = [pet1, pet2, pet3]
for i in pets:
    print(i)

#6-9 最喜欢的地方
favorite_palce ={
    "jake": ["hunan", "shanghai"],
    "bob":  ["jiangxi", "guanzhou"],
}
for name,places in favorite_palce.items():
    print(name + " the favorite place is:" )
    for place in places:
        print(place)

#6-10 喜欢的数字
like_nums = {
    "alex": [3, 33, 333],
    "jake": [6, 66, 666],
    "yi": [8,88,888],
    "wang": [9,99,999],
    "he": [1, 11, 111],
}
for name,value in like_nums.items():
    print(name + " like the numbers is " + str(value))
print()

#6-11 城市
cities = {
    "shanghai": {"country": "china", "population": "1000千万", "fact":"this is a good city"},
    "beijing": {"country": "china", "population": "1001千万", "fact":"this is a good city"},
    "shanxi": {"country": "china", "population": "1002千万", "fact":"this is a good city"},
    }
for name, values in cities.items():
    print(name + " " + values["country"] + " " +values["population"] + " " + values["fact"])

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值