forked from slgraff/edx-mitx-6.00.1x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lec11prob3.py
72 lines (53 loc) · 1.33 KB
/
lec11prob3.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# lec11prob3.py
#
# Lecture 11 - Classes
# Problem 3
#
# edX MITx 6.00.1x
# Introduction to Computer Science and Programming Using Python
# Below is a transcript of a session with the Python shell. Provide the type
# and value of the expressions being evaluated. If evaluating an expression
# would cause an error, select NoneType and write error in the box. If the
# result is a function, select function and write function in the box. As
# always, try to do this problem by hand before turning to your interpreter
# for help.
# Assume the following definitions have been made:
class Wierd(object):
def __init__(self, x, y):
self.y = y
self.x = x
def getX(self):
return x
def getY(self):
return y
class Wild(object):
def __init__(self, x, y):
self.y = y
self.x = x
def getX(self):
return self.x
def getY(self):
return self.y
X = 7
Y = 8
# provide type and value of following expressions given following transcript
# in Python shell
w1 = Weird(X, Y)
print w1.getX()
print w1.getY()
w2 = Wild(X, Y)
print w2.getX()
print w2.getY()
w3 = Wild(17, 18)
print w3.getX()
print w3.getY()
w4 = Wild(X, 18)
print w4.getX()
print w4.getY()
X = w4.getX() + w3.getX() + w2.getX()
print X
print w4.getX()
Y = w4.getY() + w3.getY()
Y = Y + w2.getY()
print Y
print w2.getY()