In this week's lectures we learnt 'recursion' which is a very useful tool for almost every programming language. It basically means a function to call itself in order to solve a problem and to make the problem easier to solve. We traced a function called nested_depth to understand recursion. Basically nested_depth returns 0 if L is not a list or it returns the number of nested depth of a list L. Code uses isinstance built-in to check whether L is a list object or not. This is used in classes as well and it is called inheritance. In this week's lab, we worked on classes using inheritance.
Week-4 Lab:
In the lab we created a class called Motorized to represent vehicles that are powered by a gas engine. This class have several attributes and methods related with the motorized object such as; number of wheels, its fuel capacity and etc. Then we test our Motorized class using unittest. Afterwards, we created subclass; Car and Bicycle that inherits the class Motorized. Classes Car and Bicycle have the same attributes with the class Motorized. After that we again tested our results and finished the exercise.
No comments:
Post a Comment