Ended up coming 4th (would have been on the podium if I got a result 0.1s faster than what I got in finals)
I'm now the fastest loser! (Fastest ever 4th place finish )
3x3 Blindfolded
Broke the Asian Record for single time (17.47s)
Came 3rd in the final round (this was very unexpected because I thought I'd place around 6-8 or so)
Part of the fastest podium ever!
Questions and Comments from last discussion
Inheritance/OOP is a difficult concept
I'll show you something that I like to do when it comes to object diagrams that I think is very helpful
Tree Recursion/Recursion
Lists + Environment Diagrams
Might do this with WWPD questions from past midterms, or something of a similar difficulty
HOFs
Will see if there's enough time for this
Announcements
Midterm on Thursday! Good luck
No discussion on Thursday
Lab 04 due today
Lab 05 and HW 03 due Wednesday
Not Thursday!!!
This discussion and next lab will be targeted towards Midterm Review
There will be 15 minutes of time at the end of this discussion to fill in the mid-semester feedback form + Go over my study tips
Will be super useful in improving your experience with CS 61A
Temperature Check
Let's see what you all want to do
Dictionaries? Yes/No
Keep in mind time constraints!
Inheritance
classDog():def__init__(self, name, owner):
self.is_alive = True
self.name = name
self.owner = owner
defeat(self, thing):print(self.name + " ate a " + str(thing) + "!")
deftalk(self):print(self.name + " says woof!")
classCat():def__init__(self, name, owner, lives=9):
self.is_alive = True
self.name = name
self.owner = owner
self.lives = lives
defeat(self, thing):print(self.name + " ate a " + str(thing) + "!")
deftalk(self):print(self.name + " says meow!")
Inheritance
Notice the redundancies in the code? One of the core foundations in this class is to not repeat yourself (DRY)
Instead, you can use inheritance to solve this problem
Syntax when creating a class is to put brackets around the class you want to inherit:
classCat(Animal):# Cat inherits the Animal class - as in, all cats are animals
...
Inheritance
classPet():def__init__(self, name, owner):
self.is_alive = True# It's alive!!!
self.name = name
self.owner = owner
defeat(self, thing):print(self.name + " ate a " + str(thing) + "!")
deftalk(self):print(self.name)
classDog(Pet):# Inherits all methods/variables from the Animal classdeftalk(self):print(self.name + ' says woof!')
Inheritance - super()
Calling super() will refer to the class's superclass
You can use the parent's method and then add on to that.
classClass(Pet):# Inherits all methods/variables from the Animal classdef__init__(self, name, owner, lives = 9):super().__init__(name, owner)
# same as calling Pet.__init__(self, name, owner) from here
self.lives = 9deftalk(self):print(self.name + ' says meow!')