/
lec11prob2.py
49 lines (39 loc) · 1.02 KB
/
lec11prob2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# lec11prob2.py
#
# Lecture 11 - Classes
# Problem 2
#
# edX MITx 6.00.1x
# Introduction to Computer Science and Programming Using Python
# 1. Consider the following code.
# What does the code print out?
# Note difference between time and self.time
class Clock(object):
def __init__(self, time):
self.time = time
def print_time(self):
time = '6:30'
print self.time
clock = Clock('5:30')
clock.print_time()
# 2. Consider the following code.
# What does the code print out?
class Clock(object):
def __init__(self, time):
self.time = time
def print_time(self, time):
print time
clock = Clock('5:30')
clock.print_time('10:30')
# 3. Consider the following problem.
# What doe the code print out?
# Are boston_clock and paris_clock different objects?
class Clock(object):
def __init__(self, time):
self.time = time
def print_time(self):
print self.time
boston_clock = Clock('5:30')
paris_clock = boston_clock
paris_clock.time = '10:30'
boston_clock.print_time()