《Python编程: 从入门到实践》动手试一试参考答案——第八章:函数

本篇博客展示了Python编程中关于函数的应用,包括显示消息、定义个人喜欢的图书、制作T恤、描述城市、创建音乐专辑、获取用户输入、展示魔术师、创建不变的魔术师列表、制作三明治、构建用户简介、创建汽车信息字典以及导入和使用模块中的函数等实例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#8-1 消息
def display_message():
    """指出你在本章学的是什么"""
    print("学习定义函数")

display_message()

#8-2 喜欢的图书
def favorite_book(title):
    """喜欢的图书"""
    print("\nOne of my favorite books is " + title + ".")

favorite_book('The old man and the sea')

#8-3 T恤
def make_shirt(T_size, T_type):
    print("\nThe T-shirt's size is: " + T_size)
    print("The T-shirt's type is: " + T_type)
    
make_shirt('39', 'freestyle')
make_shirt(T_size='39', T_type='freestyle')

#8-4 大号T恤
def make_shirt(T_size, T_type='I love python'):
    print("\nThe T-shirt's size is: " + T_size)
    print("The T-shirt's type is: " + T_type)
    
make_shirt('45')
make_shirt('40')
make_shirt('39', 'Beliver')

#8-5 城市
def describe_city(name, country='China'):
    print("\n" + name.title() +" is in " + country.title())

describe_city('hangzhou')
descri
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值