Python编程:从入门到实践第六章练习6.4

Python编程:从入门到实践第六章练习6.4



#coding:gbk

#6-7人
Taylor = {
    'first_name':'Taylor',
    'last_name':'Swift',
    'age':30,
    'city':'Nashville',
    }
    
Avirl = {
    'first_name': 'Avirl',
    'last_name': 'Lavigne',
    'age': 36,
    'city': 'Toronto',
    }
    
Skylar = {
     'first_name' : 'Skylar',
     'last_name' : 'Gray',
     'age' : 27,
     'city': 'New York',
     }
     
people = [Taylor,Avirl,Skylar]
for person in people:
	print(person)

#6-8宠物
dog = {
    'kind': 'dog',
    'owner': 'a',
    }
cat = {
    'kind': 'cat',
    'owner': 'b',
    }
bird = {
    'bird': 'bird',
    'owner': 'c',
    }

pets = [dog,cat,bird]

for pet in pets:
	print(pet)
	
#6-9喜欢的地方
favorite_places = {
    'a': 'New York',
    'b': ['Paris','Marselli'],
    'c': ['LA','Toronto','Melborn'],
    }
for name,place in favorite_places.items():
	print(name.title() + "'s favorite place is:")
	print(place)      #此处想要做出制表符美化输出,但是发现在value为列表的情况下,无法通过在前添加制表符实现空格,后尝试直接插入空格发现不论是制表符还是直接插入,都无法在列表前加入空格
	
	
#6-10喜欢的数字
favorite_numbers = {
    'a': 1,       
    'b': [1,2,3],
    'c': [3,4],
    'd': [4,5],
    'e': [5,6,7,8],
    }
for name,number in favorite_numbers.items():  
	print(name.title() + "'s favorite numbers are:")
	print(number)

#6-11城市
cities = {
     'NY': {'country': 'US',
     'population': 1,
     'fact': 'prosperous',
     },
     
     'Paris':{'country': 'France',
     'population': 2,
     'fact': 'luxury',
     },
     
     'Amoy': {'country': 'China',
     'population': 3,
     'fact': 'green',
     }
     }
for city,info in cities.items():
	print("\nCity: " + city)
	pop = info['population']
	fac = info['fact']
	print("\tPopulation:" + str(pop))
	print("\tFact:" + fac.title())
	
#6-12扩展
#略




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值