字典

6-1

My_frind = {'frist_name': 'yang', 'last_name': 'ping', 'age': '23','city': 'ning xia'}
print(My_frind)
{'frist_name': 'yang', 'last_name': 'ping', 'age': '23', 'city': 'ning xia'}

6-2

Love_number = {'yang ping': 4, 'weijia': 8, 'wenwen': 9}
print("yang ping love number is:" + str(Love_number['yang ping']))
print("wei jia  love number is:" + str(Love_number['weijia']))
print("wen wen love number is:" + str(Love_number['wenwen']))
yang ping love number is:4
wei jia  love number is:8
wen wen love number is:9

6-3

vocabulary = {
    '爱情': '喜欢的人之间的感情',
    '友谊': '朋友之间的情谊',
    '亲情': '家人之间的情谊'
    }
print("爱情的含义是:" + "\n   " + vocabulary['爱情'] + ".")
print("友谊的含义是:" + "\n   " + vocabulary['友谊'] + ".")
print("亲情的含义是:" + "\n   " + vocabulary['亲情'] + ".")
爱情的含义是:
   喜欢的人之间的感情.
友谊的含义是:
   朋友之间的情谊.
亲情的含义是:
   家人之间的情谊.

6-4

vocabulary = {
    '爱情': '喜欢的人之间的感情',
    '友谊': '朋友之间的情谊',
    '亲情': '家人之间的情谊'
    }
for key, value in vocabulary.items():
    print("\ncihiu:" + key)
    print("hanyi:" + value)
cihiu:爱情
hanyi:喜欢的人之间的感情

cihiu:友谊
hanyi:朋友之间的情谊

cihiu:亲情
hanyi:家人之间的情谊

6-5

rivers_0 = {'长江': '中国', '亚马孙河': '南美', '密西西比河': '美国',}
for nlie, egypt in rivers_0.items():
    print(str(nlie) + "流经" + str(egypt) + ".\n")
for nlie in rivers_0.keys():
    print(str(nlie))
for egypt in rivers_0.values():
    print(str(egypt))
长江流经中国.

亚马孙河流经南美.

密西西比河流经美国.

长江
亚马孙河
密西西比河
中国
南美
美国

6-6

favorite_language = {
    'jen': 'python',
    'sarah': 'c',
    'edward': 'ruby',
    'phil': 'python',
    }
suvery_list = ['phil','jen','rew']
for name in favorite_language.keys():
    print(name.title())
    if name in suvery_list:
        print("Hi " + name.title() + "I see you learn " + 
             favorite_language[name].title() + "!")
if 'rew' not in favorite_language.keys():
    print("rew,please take our poll")
Jen
Hi JenI see you learn Python!
Sarah
Edward
Phil
Hi PhilI see you learn Python!
rew,please take our poll

6-7

My_frind = {
    'yangping': {
        'age': 23,
        'city': 'guyuan',
        },
    'zhaoyuxai': {
        'age': '22',
        'city': 'pengyang'
        },
    }
for name, use_info in My_frind .items() :
    print("\nmy frinds: " + name)
    age = use_info['age']
    city = use_info['city']
    print("\tage: " + str(age))
    print("\tcity: " + city.title())
my frinds: yangping
	age: 23
	city: Guyuan

my frinds: zhaoyuxai
	age: 22
	city: Pengyang

6-8

cat = {'leixing': 'buru', 'zhuren': 'xioa li',}
dog = {'leixing': 'quanlei', 'zhuren': 'xiaozhao'}
pets = [cat,dog]
for pet in pets:
    print(pet)
{'leixing': 'buru', 'zhuren': 'xioa li'}
{'leixing': 'quanlei', 'zhuren': 'xiaozhao'}

6-9

favorite_place ={
    'jone': ['yunnan', 'guilin', 'jiaxing'],
    'lucy': ['riben', 'xinxilan'],
    'ruiwen': ['meiguo', 'deguo'],
    }
for name, plalces in favorite_place.items():
    print("\n" + name.title() + "'s favorite place are: ")
    for place in plalces:
        print("\t" + place.title())
Jone's favorite place are: 
	Yunnan
	Guilin
	Jiaxing

Lucy's favorite place are: 
	Riben
	Xinxilan

Ruiwen's favorite place are: 
	Meiguo
	Deguo

6-10

Love_number = {
    'yang ping': [2,3],
    'weijia': [4,7],
    'wenwen': [9,2],
    }
for name,number in Love_number.items():
    print("\n" + name.title() + "喜欢的数字是:")
    for num in number:
        print("\t" + str(num))

Yang Ping喜欢的数字是:
	2
	3

Weijia喜欢的数字是:
	4
	7

Wenwen喜欢的数字是:
	9
	2

6-11

cities = {
    '成都': {
        'country': '中国',
        'population': '6万',
        'fact': '暴力城市之一',
        },
    '宁夏': {
        'country': '中国',
        'population': '7万',
        'fact': '回族自治自区',
        },
    }
for city, city_info in cities.items():
    print("\n" + city.title() + '的基本信息: ')
    country = city_info['country']
    population = city_info['population']
    fact = city_info['fact']
    print("\t" + country)
    print("\t" + population)
    print("\t" + fact)
    
成都的基本信息: 
	中国
	6万
	暴力城市之一

宁夏的基本信息: 
	中国
	7万
	回族自治自区
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值