Python编程:从入门到实践 动手试一试 6.1-6.12

#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. 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值