当前位置:   article > 正文

《Python编程从入门到实践》练习题代码实现第六章_python编程从入门到精通练习6

python编程从入门到精通练习6
  1. #6-1
  2. message={'first_name':'xiao','last_name':'ming',
  3. 'age':'18','city':'beijing'}
  4. print(message['first_name'])
  5. print(message['last_name'])
  6. print(message['age'])
  7. print(message['city'])
  8. #6-2 喜欢的数字
  9. message={'a':'7','b':'1','c':'3','d':'8','e':'9'}
  10. print(message['a'])
  11. print(message['b'])
  12. print(message['c'])
  13. print(message['d'])
  14. print(message['e'])
  15. #6-3 词汇表
  16. cihuibiao={'#':'注释','list':'list'}
  17. print('#'+':'+cihuibiao['#']+'\n')
  18. print('list'+':'+cihuibiao['list']+'\n')
  19. #6-4 词汇表2
  20. #6-5 河流
  21. rivers={
  22. 'Rhine':'Switzerland',
  23. 'changJiang':'china',
  24. 'nile':'egypt',
  25. }
  26. for river,country in rivers.items():
  27. print('The '+river.title()+'runs through the '+country.title()+'.')
  28. #6-7
  29. people={
  30. 'name_1':{
  31. 'first':'xiao',
  32. 'last':'ming',
  33. 'city':'beijing'
  34. },
  35. 'name_2':{
  36. 'first':'zhang',
  37. 'last':'san',
  38. 'city':'xian',
  39. }
  40. }
  41. for username,user in people.items():
  42. print("用户:"+username)
  43. name=user['first']+" "+user['last']
  44. city=user['city']
  45. print("全名:"+name.title()+" 住址:"+city.title())
  46. #6-8 宠物
  47. pets={
  48. 'pet_1':{
  49. 'pet_name':'lunlun',
  50. 'classify':'dog',
  51. 'master':'zi',
  52. },
  53. 'pet_2':{
  54. 'pet_name':'aoao',
  55. 'classify':'cat',
  56. 'master':'yang',
  57. }
  58. }
  59. for key,value in pets.items():
  60. print(key.title()+"的名字是:"+value['pet_name'].title()+
  61. ",它是只"+value['classify']+",它的主人是:"+value['master'])
  62. #6-9 喜欢的地方
  63. favorite_places={
  64. 'man_1':'beijing',
  65. 'man_2':'yunnan',
  66. 'man_3':'sanya',
  67. }
  68. for key,value in favorite_places.items():
  69. print(key.title()+"最喜欢的地方是"+value.title())
  70. #6-10 喜欢的数字
  71. favorite_numbers={
  72. 'a':'3,7',
  73. 'b':'1,9',
  74. 'c':'0',
  75. }
  76. for key,value in favorite_numbers.items():
  77. print(key.title()+"喜欢的数字是"+value.title())
  78. #6-11 城市
  79. cities={
  80. 'sanya':{'country':'china','population':'14','fact':'hot'},
  81. 'newyork':{'country':'america','population':'3','fact':'hot'},
  82. }
  83. for key,value in cities.items():
  84. print(key.title()+"属于"+value['country']+",这个国家有"+
  85. value['population']+"亿人,这个城市"+value['fact'])

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小惠珠哦/article/detail/1007564
推荐阅读
相关标签
  

闽ICP备14008679号