8-1消息
编写一个名为display_message()的函数,它打印一个句子,指出你在本章学的是什么。调用这个函数,确认显示的消息正确无误。
def display_message():
print("I have learned how to define a function and how to deliver parameters to function.")
display_message()
build
I have learned how to define a function and how to deliver parameters to function.
[Finished in 0.2s]
8-2 喜欢的图书
编写一个名为favorite_book()的函数,其中包含一个名为title的形参。这个函数打印一条消息,如One of my favorite books is Alice in Wonderland。调用这个函数,并将一本图书的名称作为实参传递给它。
def favorite_book(title):
print("One of my favorite books is " + title.title() + ".")
favorite_book('alice in wonderland')
#实参的引号不能忘
build
One of my favorite books is Alice In Wonderland.
[Finished in 0.1s]
习题8-7 专辑
(1)
def make_album(album_name, singer_name):
album = {
'album': album_name, 'singer': singer_name}
return album
album_information = make_album('Innocence', 'Avaril')
print(album_information)
album_information = make_album('Fantasy', 'Jay')
print(album_information)
album_information = make_album('Baby', 'Biber')
print