Python编程:从入门到实践 动手试一试 6.1-6.12
2020-02-06 08:05
417 查看
#6.1 people
infos = {'first_name':'Airous', 'last_name':'Wang', 'age':'28', 'city':'Beijin' } print(infos["first_name"]) print(infos['last_name']) print(infos['age']) print(infos['city']) #6.2 favorite numbers list_of_people = {'benji':'12', 'airous':'6', 'ricky':'15', 'simone':'18', 'karl':'42'} print(list_of_people['airous']) print(list_of_people['benji']) print(list_of_people['ricky']) print(list_of_people['simone']) print(list_of_people['karl'])
#6.3 vocabulary form
meanings = {'append':'the way that insert an element to the end of the list or tuple', 'list':'a group of elements together, all of which is changeable', 'tuple':'similar as list but the elements cannot be changed unless you redefine' } print(meanings) user_0 = { 'username': 'efermi', 'first': 'enrico', 'last': 'fermi', } for key, value in user_0.items(): print("\nKey: " + key) print("Value: " + value)
#6.4 vocabulary form 2
meanings = {'append':'the way that insert an element to the end of the list or tuple', 'list':'a group of elements together, all of which is changeable', 'tuple':'similar as list but the elements cannot be changed unless you redefine' } for key, value in meanings.items(): print("\nKey: " + key.title()) print("Value: " + value)
#6.5 rivers
rivers = {'nile':'egypt', 'yellow river':'china', 'mississippi':'america' } for k, v in rivers.items(): print("The " + k.title() + " runs through " + v.title()) for name in rivers.keys(): print("Name: " + name.title()) for country in rivers.values(): print("Country: " + country.title())
#6.6 inspection
favorite_languages = { 'jen': 'python', 'sarah': 'c', 'edward': 'ruby', 'phil': 'python', } list_of_inspection = ['jen', 'sarah', 'benji', 'phil'] for name in favorite_languages.keys(): if name in list_of_inspection: print(name.title() + ", thank you for helping us!") else: print(name.title() + ", please help us to inspect.")
#6.7 people
infos = {"Airous": {'first name': 'Airous', 'last name':'Wang', 'age':'28', 'city':'Beijin'}, "Benji": {'first name': 'Benji', 'last name':'He', 'age':'28', 'city':'Shenzhen'}, "Ricky": {'first name': 'Ricky', 'last name':'Mak', 'age':'60', 'city':'Shenzhen'} } for name, info in infos.items(): print("First name: " + name.title() + "\nLast name: " + info['last name'] + "\nAge: " + info["age"]+ "\nCity: " + info['city'] + "\n" )
#6.8 pets
puppy = {'type':'retriever', 'master':'Benji'} cat = {'type':'chinese li hua', 'master':'ricky'} parrot = {'type':'howl', 'master':'leo'} pets = [puppy,cat,parrot] for info in pets: print(info)
#6.9 places people like
favorite_places = {'Benji':['New York', 'Iceland', 'Glasgow'], 'Ricky':['Hong Kong', 'Shenzhen', 'London'], 'Karl':['Shanghai', 'Pari', 'Huston'] } for name, places in favorite_places.items(): print("\nName: " + name.title()) print("Favorite Places are: ") for p in places: print(str(p))
#6.10
#skip it as its similarity.
#6.11 cities
cities = {'shenzhen':{'country':'china', 'population':'8 millions', 'fact':'young city'}, 'hong kong':{'country':'china', 'population':'7 millions', 'fact':'crowd city'}, 'beijin':{'country':'china', 'population':'10 millions', 'fact':'biggest city'} } for city, information in cities.items(): print("\nName of City: " + city.title()) print("Informations of City: " + "\n\tCountry: " + information['country'].title() + "\n\tPopulation: " + information['population'].title() + "\n\tFact: " + information['fact'].title() )
#6.12
#skip it.
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- Python编程:从入门到实践 动手试一试 6.1-6.12
- Python编程:从入门到实践 动手试一试 7.1-7.10
- Python编程从入门到实践动手试一试习题 15-1至15-5
- Python编程:从入门到实践 动手试一试 8.1-8.14
- Python编程:从入门到实践 动手试一试 8.1-8.14
- Python编程:从入门到实践 动手试一试 7.1-7.10
- Python学习 第二天任务 (二:【基于Python编程从入门到实践】第二章 数字和注释 书本及动手试一试)
- Python入门与实践 Chapter 4 动手试一试
- Python入门与实践 Chapter 8 动手试一试
- Python入门与实践 Chapter 6 动手试一试
- Python入门与实践 Chapter 7 动手试一试
- Python学习 第二天任务 (一:【基于Python编程从入门到实践】第二章 变量和字符串 书本及动手试一试)
- Python学习 第一天任务 (四:【基于Python编程从入门到实践】动手试一试)
- Python入门与实践 Chapter 5 动手试一试
- Python编程:从入门到实践--十到十一章
- 第五天任务 (【基于Python编程从入门到实践】第五章 if语句 书本及动手试一试)
- 《Python 编程-从入门到实践》2-1~2-11
- 关于Python编程从入门到实践中,动手试一试5-10
- Python编程从入门到实践自我整合 第七章
- <Python编程从入门到实践--web应用程序> 学习笔记