
习题31 做出决定
1 | print("""You enter a dark room with two doors, |
习题32 循环和列表
1 | the_count = [1,2,3,4,5] |
习题33 while循环
1 | i = 0 |
习题34 访问列表的元素
1 | #animals = ['bear','tiger','penguine','zebra'] |
习题35 分支和函数
1 | from sys import exit |
习题36 设计和调试
1 |
习题37 复习各种符号
1 |
习题38 列表的操作
1 | ten_things = "Apples Oranges Crows Telephone Light Sugar" |
习题39 字典,可爱的字典
1 | states = { |
习题40 模块、类和对象
class Song(object):
def __init__(self, lyrics):
self.lyrics = lyrics
def sing_me_a_song(self):
for line in self.lryics:
print(line)
happy_bday = Song(["Happy birthday to you",
"I don't want to get sued",
"So I'll stop right there"])
bulls_on_parade = Song(["They rally aroud the family",
"With pockets full of shells"])
happy_bday.sing_me_a_song()
bulls_on_parade.sing_me_a_song()
# __init__ 左右下划线是两个