- (10%)
Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
class Student:
def __init__(n, w, h): # Constructor
name = n
weight = w
height = h
def main():
a = Student("Alice", 65, 1.65)
b = Student("Bob", 75, 1.75)
print(a.weight, b.height)
main()
- (10%)
Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def move(self, dx, dy): # method
self.x = self.x + dx # instance variable
self.y = self.y + dy
a = Point(3, 5)
a.move(4,6)
print(a.x, a.y)
- (10%)
Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
class Point:
def __init__(self, x, y):
self.x, self.y = x, y
def move(self, dx, dy):
x = dx
y = dy
def main():
a = Point(4,6)
a.move(3, 5)
print(a.x, a.y)
main()