Created
December 3, 2019 02:08
-
-
Save calthoff/104bb758e001df4b4a5eb643bc5d0a20 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Exercise 1 Solution | |
class Square: | |
square_list = [] | |
def __init__(self): | |
self.square_list.append(self) | |
# Exercise 2 Solution | |
class Square: | |
def __init__(self, s1): | |
self.s1 = s1 | |
def calculate_perimeter(self): | |
return self.s1 * 4 | |
def __repr__(self): | |
return "{} by {} by {} by {}".format(self.s1, self.s1, self.s1, self.s1) | |
# Exercise 3 Solution | |
def same(obj1, obj2): | |
return obj1 is obj2 | |
class Square: | |
def __init__(self): | |
pass |
def are_same_object(obj1, obj2):
return obj1 is obj2
obj_a = [1, 2, 3]
obj_b = [1, 2, 3]
obj_c = obj_a
print(are_same_object(obj_a, obj_b)) # Output: False
print(are_same_object(obj_a, obj_c)) # Output: True
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output:
The Udemy course will not evaluate this exercise, but hopefully this helps someone else understand the problem.