当前位置:   article > 正文

《Python编程从入门到实践》第八章 函数 知识点及习题_python 练习 8.12

python 练习 8.12

1. 知识点

2. 练习·

  1. # 练习8.1
  2. def display_message():
  3. print("theme")
  4. display_message()
  5. # 练习8.2
  6. def favorite_book(title):
  7. print(f"one of my favorite book is {title}")
  8. print("please imput your favorite book")
  9. title = input()
  10. favorite_book(title)
  11. # 练习 8.3
  12. def make_shirt(size,words):
  13. print(f"shirt's size is {size} and words is \"{words}\" ")
  14. make_shirt("xl","happy")
  15. # 练习 8.4 大号T
  16. def make_shirt(size,words="i ove python"):
  17. print(f"shirt's size is {size} and words is \"{words}\" ")
  18. make_shirt("xl")
  19. make_shirt("l")
  20. make_shirt("s","happy")
  21. # 练习8.5 城市
  22. def describe_city(name,coutry="China"):
  23. print(f"{name.title()} is in {coutry.title()}")
  24. describe_city("Xian")
  25. describe_city("hunan")
  26. describe_city("London","England")
  27. def build_person (first_name,last_name,age=None):
  28. person={'first':first_name, 'last':last_name}
  29. if age:
  30. person['age']=age
  31. return person
  32. musician=build_person('jia','chen','24')
  33. print(musician)
  34. # 练习8.6 城市名
  35. def describe_city(name,coutry):
  36. print(f"{name.title()}{coutry.title()}")
  37. describe_city("Xian","China")
  38. describe_city("London","England")
  39. # 练习8.7 专辑
  40. def make_album(singer, name, number='None'):
  41. album={"Singer":singer, 'Name':name}
  42. if number:
  43. album['Number']=number
  44. return album
  45. Album=make_album("vava","cake","9")
  46. print(Album)
  47. Album=make_album("gai","caker","4")
  48. print(Album)
  49. # 练习8.8 用户的专辑
  50. def make_album(singer, name, number='None'):
  51. album={"Singer":singer, 'Name':name}
  52. if number:
  53. album['Number']=number
  54. return album
  55. while True:
  56. singer=input("tell me the singer of album\n")
  57. if singer=='q':
  58. break
  59. name=input("tell me the name of album\n")
  60. if name=='q':
  61. break
  62. Album = make_album(singer, name)
  63. print(Album)
  1. # 练习8.9
  2. messages=['hello','bye','see you','watch out']
  3. send_messages=[]
  4. def show_message(messages,send_messages):
  5. for message in messages:
  6. print(message)
  7. send_messages.append(message)
  8. def send_message(send_messages):
  9. for send_message in send_messages:
  10. print(send_message)
  11. show_message(messages[:],send_messages)
  12. send_message(send_messages[:])
  13. # 练习8.10 消息归档
  14. # 练习8.12 三明治
  15. def make_sandwich(*toppings):
  16. print("Making a sandwich with the following toppings ")
  17. for topping in toppings:
  18. print(f"- {topping}")
  19. make_sandwich('tomato','egg','potato')
  20. # 练习8.13 用户简介
  21. def build_profile(first, last,**user_info):
  22. user_info['first_name']=first
  23. user_info['last_name']=last
  24. return user_info
  25. user_profile=build_profile('shao', 'tang', location='tianjing', field=' construction',weigh='210')
  26. print(user_profile)
  27. # 练习8.14 汽车
  28. def make_car(maker,size ,**imformation):
  29. imformation['Manufacturers']=maker
  30. imformation['Models']=size
  31. return imformation
  32. car=make_car('subaru','outback',color='blue',tow_package=True)
  33. print(car)

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

闽ICP备14008679号