当前位置:   article > 正文

python快速编程入门第二版课后编程题答案_python快速编程入门第二版黑马程序员课后答案

python快速编程入门第二版黑马程序员课后答案

本篇文章给大家谈谈python快速编程入门第二版课后编程题答案,以及python快速编程入门第二版课后题答案,希望对各位有所帮助,不要忘了收藏本站喔。

8-1

  1. def display_message():
  2. print("study function")
  3. display_message()

 8-2

  1. def favorite_book(title):
  2. print(f"One of my favorite books is {title.title()}")
  3. book = input('whatis your favorite book?')
  4. favorite_book(book)

 8-3

  1. def make_shirt(size, word):
  2. print(f"This t-shirt is {size} and is printed with {word} characters")
  3. word = input("it is printed your shirt:")
  4. size = input("size:")
  5. make_shirt(size, word)

8-4

  1. #打印 I Love python
  2. def make_shirt(size, word='I love python'):
  3. print(f"This t-shirt is {size} and is printed with {word} characters")
  4. make_shirt(size='10')
  5. #打印其他语句
  6. def make_shirt(size, word='I love python'):
  7. print(f"This t-shirt is {size} and is printed with {word} characters")
  8. make_shirt(size='10',word='I love C++')

8-5

  1. def describe_city(name, country='china'):
  2. print(f"{name.title()} is in {country.title()}")
  3. describe_city('beijing')
  4. describe_city('tokyo', 'japan')
  5. describe_city(name='Washington', country='america')

8-6

  1. def city_country(name, country):
  2. country_name = f"{name} , {country}"
  3. return country_name.title()
  4. name1 = city_country('beijing', 'china')
  5. name2 = city_country('tokyo', 'japan')
  6. name3 = city_country(name='Washington', country='america')
  7. print(name1)
  8. print(name2)
  9. print(name3)

 8-7

  1. #使用国家代替专辑
  2. def make_album(name, album, num=''):
  3. album_name = {'name': name, 'album_name': album}
  4. if num:
  5. album_name['number'] = num
  6. return album_name
  7. name1 = make_album('beijing', 'china',5)
  8. name2 = make_album('tokyo', 'japan',10)
  9. name3 = make_album(name='Washington', album='america')
  10. print(name1)
  11. print(name2)
  12. print(name3)

8-8

  1. def make_album(name, album, number=''):
  2. album_name = {'name': name, 'album_name': album}
  3. if number:
  4. album_name['number'] = number
  5. return album_name
  6. flag = True
  7. while flag:
  8. name = input("Input singer's name:")
  9. album = input("Input album's name:")
  10. m = make_album(name, album)
  11. print(m)
  12. leave = input("Do you input enough?(y/n)")
  13. if leave.upper() == 'Y':
  14. break

 8-9

  1. def pri_text(texts):
  2. for text in texts:
  3. print(text)
  4. texts = ['show', 'person', 'country', 'day']
  5. pri_text(texts)

8-10

  1. def send_messages(send_message, sent_message ):
  2. while send_message:
  3. m = send_message.pop()
  4. sent_message.append(m)
  5. print(f"{send_message}")
  6. print(f"{sent_message}")
  7. send_message = ['show', 'person', 'country', 'day']
  8. sent_message = []
  9. send_messages(send_message, sent_message)

8-11 

  1. def send_messages(send_message, sent_message):
  2. while send_message:
  3. m = send_message.pop()
  4. sent_message.append(m)
  5. print(f"{send_message}")
  6. print(f"{sent_message}")
  7. send_message = ['show', 'person', 'country', 'day']
  8. sent_message = []
  9. send_messages(send_message[:], sent_message[:])
  10. print(f"{send_message}")
  11. print(f"{sent_message}")
  1. #结果
  2. []
  3. ['day', 'country', 'person', 'show']
  4. ['show', 'person', 'country', 'day']
  5. []

8-12

  1. def make_pizza(*toppings):
  2. print("\nMaking a pizza with the following toppings:")
  3. for topping in toppings:
  4. print(f"- {topping}")
  5. make_pizza('pepperoni')
  6. make_pizza('mushrooms', 'green peppers')
  7. make_pizza('mushrooms', 'green peppers', 'extra cheese')
  8. #输出
  9. Making a pizza with the following toppings:
  10. - pepperoni
  11. Making a pizza with the following toppings:
  12. - mushrooms
  13. - green peppers
  14. Making a pizza with the following toppings:
  15. - mushrooms
  16. - green peppers
  17. - extra cheese

 8-13

  1. def build_profile(first, last, **user_info):
  2. user_info['first_name'] = first
  3. user_info['last_name'] = last
  4. return user_info
  5. user_profile = build_profile('alice', 'harden',
  6. location='xian',
  7. filed='physics')
  8. print(user_profile)
  9. #输出
  10. {'location': 'xian', 'filed': 'physics', 'first_name': 'alice', 'last_name': 'harden'}

8-14

  1. def make_car(manufacturer, model, **user_info):
  2. user_info['manufacturer'] = manufacturer
  3. user_info['model'] = model
  4. return user_info
  5. car = make_car('subaru', 'outback', color='blue', two_package=True)
  6. print(car)
  7. #输出
  8. {'color': 'blue', 'two_package': True, 'manufacturer': 'subaru', 'model': 'outback'}

文章知识点与官方知识档案匹配,可进一步学习相关知识
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/402557
推荐阅读
相关标签
  

闽ICP备14008679号