Class Inheritance seemed like the easiest topic for the week in my opinion. It just seems to make sense how you can build a general class and then more specific ones that import from it (for example, the class Cat(Animal) inherits features from the class Animal).
I also got more specialized with Recursion which we talked about the past week.We also compared Stacks and Queues, how they can be modified, or if flexible enough, extend some of their features (using Stack attribute in new classes).
We then spent a lot of time focusing on Exceptions and how to raise them, create class for them, use already built-in ones. Very interesting how Exceptions are raised in real-life examples. The teacher mentioned an example for Exceptions which focused on how chat clients would work. The code would attempt to establish a connection and if failed, try and reconnect 5 seconds later. The code is pasted below:
# ConnectionError is a built-in subclass of Exception
if __name__ == "__main__":
running = True
while running:
try:
con = establish_connection()
run_with_connection(con)
except ConnectionError:
system.wait(5) # wait 5 seconds before trying again
# todo: notify user, and increase parameter 5 each time
Assigned Topic for Week 3:
- Object-Oriented Programming is a way of programming that uses concepts such as "objects" and methods. The objects are usually class instances and are used to interact between each other. Python is a programming language that is object-oriented as variables and classes are used in order to solve problems.
I finished both exercises due for this course relatively easily with some issues surfacing in the second Exercise however it turns out it was just a stupid mistake from myself (forgot to add an Exception) which I fixed and the automarker gave me full marks. Let's hope it keeps going that way. I have downloaded all the required files and read the first Assignment. Planning on working on it this weekend to get it done early... Here goes nothing!
No comments:
Post a Comment