笨办法学python加分习题39
2018-02-09 14:51
411 查看
python版本:3 若有错误,敬请指出 模块名称:测试.py#加分习题39
class Song():
def __init__(self,lyrics,name):
self.lyrics = lyrics
self.name = name
def sing_me_a_song(self):
for line in self.lyrics:
print(line)
def singer_name(self):
print(self.name.title())
happy_bday = Song(["Happy birthday to you",
"I don't want to get sued",
"So I'll stop right there"],'gray')
bulls_on_parade = Song(["They rally around the familly",
"With pockets full of shells"], 'gray')
happy_bday.singer_name()
happy_bday.sing_me_a_song()
bulls_on_parade.singer_name()
bulls_on_parade.sing_me_a_song()
#加分习题
#1. 使用这种方式写更多的歌进去,确定自己懂得了传入的歌词是一个字符串列表。
#2. 将歌词放到另一个的变量里边,然后再类里边使用这一个新定义的变量。
#3. 试着看能不能给它加些新功能,不知道怎么做也没关系,只要试着去做也行,弄坏了也没关系,
#反正它也不会疼。
#4. 在网上搜索一下“object oriented programming”(中文:面向对象编程),给自己洗洗脑。弄
#不懂也没关系,其实里边有一半的东西对我来说也是没有意义的。
#1略
#2?
#3如上
#4面向对象的语言支持的概念包括:类与对象、继承、多态
运行截图:
class Song():
def __init__(self,lyrics,name):
self.lyrics = lyrics
self.name = name
def sing_me_a_song(self):
for line in self.lyrics:
print(line)
def singer_name(self):
print(self.name.title())
happy_bday = Song(["Happy birthday to you",
"I don't want to get sued",
"So I'll stop right there"],'gray')
bulls_on_parade = Song(["They rally around the familly",
"With pockets full of shells"], 'gray')
happy_bday.singer_name()
happy_bday.sing_me_a_song()
bulls_on_parade.singer_name()
bulls_on_parade.sing_me_a_song()
#加分习题
#1. 使用这种方式写更多的歌进去,确定自己懂得了传入的歌词是一个字符串列表。
#2. 将歌词放到另一个的变量里边,然后再类里边使用这一个新定义的变量。
#3. 试着看能不能给它加些新功能,不知道怎么做也没关系,只要试着去做也行,弄坏了也没关系,
#反正它也不会疼。
#4. 在网上搜索一下“object oriented programming”(中文:面向对象编程),给自己洗洗脑。弄
#不懂也没关系,其实里边有一半的东西对我来说也是没有意义的。
#1略
#2?
#3如上
#4面向对象的语言支持的概念包括:类与对象、继承、多态
运行截图:
相关文章推荐
- 笨办法学python加分习题32
- 笨办法学python加分习题35
- 笨办法学python加分习题28
- 笨办法学python加分习题29
- 笨办法学python加分习题16
- 笨办法学python加分习题26
- 笨办法学Python习题35-加分习题
- 笨办法学python加分习题20
- 笨办法学python加分习题38
- 笨办法学Python-习题37-39
- 笨办法学python加分习题24
- 笨办法学python加分习题30
- 笨办法学python加分习题21
- 笨办法学python(习题39)——items()、get()、
- 笨办法学python加分习题31
- 笨办法学python加分习题34
- 笨办法学python加分习题36
- 笨办法学python加分习题15
- 笨办法学python加分习题17
- Python调用SIFT出现的问题:No such file or directory: '*.sift' 解决办法,超好用