Python练习 Chapter 8

8-1 消息 : 编写一个名为display_message() 的函数, 它打印一个句子, 指出你在本章学的是什么。 调用这个函数, 确认显示的消息正确无误。

def display_message():
    print("In this chapter, we will learn function of Python.")

display_message()

结果:

In this chapter, we will learn function of Python.

8-2 喜欢的图书 : 编写一个名为favorite_book() 的函数, 其中包含一个名为title 的形参。 这个函数打印一条消息, 如One of my favorite books is Alice in Wonderland 。 调用这个函数, 并将一本图书的名称作为实参传递给它。

def favorite_book(title):
    print("One of my favourite books is " + title + '.')

favorite_book("Alice in Wonderland")

结果:

One of my favourite books is Alice in Wonderland.
8-3 T 恤 : 编写一个名为 make_shirt() 的函数, 它接受一个尺码以及要印到 T 恤上的字样。 这个函数应打印一个句子, 概要地说明 T 恤的尺码和字样。
使用位置实参调用这个函数来制作一件
T 恤; 再使用关键字实参来调用这个函数。

def make_shirt(size, letter):
    print("\nHere is the information of your T-shirt.")
    print("Size: " + size)
    print("Letter: " + letter)

make_shirt('M', "I'm Chinese")
make_shirt(letter = "I'm Chinese", size = 'M')

结果:

Here is the information of your T-shirt.
Size: M
Letter: I'm Chinese

Here is the information of your T-shirt.
Size: M
Letter: I'm Chinese

8-4 大号T恤 : 修改函数make_shirt() , 使其在默认情况下制作一件印有字样“I love Python”的大号T恤。 调用这个函数来制作如下T恤: 

一件印有默认字样的大号T恤、一件印有默认字样的中号T恤和一件印有其他字样的T恤(尺码无关紧要) 。

def make_shirt(size='L', letter='I love Python'):
    print("\nHere is the information of your T-shirt.")
    print("Size: " + size)
    print("Letter: " + letter)

m
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值