1. Classes and objects

1class Television:
2    def __init__(self):
3        self.connected = False
4        self.channel = 2
5
6
7room_tv = Television()
8living_room_tv = Television()
9print(room_tv.connected)
10print(room_tv.channel)
11living_room_tv.connected = True
12living_room_tv.channel = 5
13print(living_room_tv.connected)
14print(living_room_tv.channel)
line that just executed

next line to execute

Print output (drag lower right corner to resize)
Frames
Objects

Activity: CodeLens 1.1 (cl_l25_1a_en)

1class Television:
2    def __init__(self):
3        self.connected = False
4        self.channel = 2
5
6    def change_channel_down(self):
7        self.channel -= 1
8
9    def change_channel_up(self):
10        self.channel += 1
11
12
13tv = Television()
14tv.change_channel_up()
15tv.change_channel_up()
16print(tv.channel)
17tv.change_channel_down()
18print(tv.channel)
line that just executed

next line to execute

Print output (drag lower right corner to resize)
Frames
Objects

Activity: CodeLens 1.2 (cl_l25_1b_en)

You have attempted 1 of 2 activities on this page