-
-
Save calthoff/104bb758e001df4b4a5eb643bc5d0a20 to your computer and use it in GitHub Desktop.
# 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 |
Solution to Exercise 3
`def same(obj1, obj2):
return obj1 is obj2
class Square:
def __init__(self):
pass
class Square2:
def __init__(self):
pass`
He is not going to give you the Answers as you can see all you are doing at this point i figure is getting some what of an understanding of how python works lucky if you even get close with out looking up the answer because Python is hard one Goggle search compared it to C++, #C what ever its easy to learn but HELL no it is not easy, easy to learn. This is a run down of Python so it is what it is dude.
Second of all i think even if you do go out into the field for this most of the skills would be OJT so yeah that's just what I figure this is just Python. Not HTML, Java script, PHP ...... there are over 150 different coding languages this is just one of them. So for an online book this is what it is. Its cool they even did this to let people figure out how this works.
Im not being mean I just don't like people complaining every time.
i don't feel like they are complaining, but even if so, it's warranted. these are the instructions for exercise 3:
Write a function that takes two objects as parameters and returns True if they are the same object, and False if not
it will not pass unless you name the function 'same'
class Person():
def __init__(self):
pass
def check_if_same(obj1, obj2):
if obj1 is obj2:
return obj1 is obj2
else:
return obj1 is obj2
p1 = Person()
same_p = p1
p2 = Person()
another_p = p2
print(check_if_same(p1, same_p))
print(check_if_same(same_p, another_p))
Output:
True
False
The Udemy course will not evaluate this exercise, but hopefully this helps someone else understand the problem.
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
Exercise 3 solution is not working. Tried many times but an error occur;
importerror: cannot import name: same