Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
10 views

Python_OOP_Exercise

The document outlines exercises for beginners to practice the four pillars of Object-Oriented Programming (OOP) in Python 3. It includes tasks related to classes and objects, attributes and methods, abstraction and encapsulation, inheritance, and polymorphism. Each exercise provides specific requirements for creating programs that demonstrate these OOP concepts.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Python_OOP_Exercise

The document outlines exercises for beginners to practice the four pillars of Object-Oriented Programming (OOP) in Python 3. It includes tasks related to classes and objects, attributes and methods, abstraction and encapsulation, inheritance, and polymorphism. Each exercise provides specific requirements for creating programs that demonstrate these OOP concepts.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

The Four Pillars of OOP in Python 3 for Beginners

EXERCISE - CLASSES AND OBJECTS

Write and object oriented program that performs the following


tasks:
1. Define a class called "Employee" and create an instance
of that class
2. Create an attribute called name and assign it with a
value
3. Change the name you previously defined within a
method and call this method by making use of the object you
created

Created by Febin George


The Four Pillars of OOP in Python 3 for Beginners

EXERCISE - ATTRIBUTES AND METHODS

Write an object oriented program to create a precious stone.


Not more than 5 precious stones can be held in possession at a
given point of time. If there are more than 5 precious stones,
delete the first stone and store the new one.

Created by Febin George


The Four Pillars of OOP in Python 3 for Beginners

EXERCISE - ABSTRACTION AND ENCAPSULATION

Similar to a library management system, write a program to


provide layers of abstraction for a car rental system.
Your program should perform the following:
1. Hatchback, Sedan, SUV should be type of cars that are
being provided for rent
2. Cost per day:
Hatchback - $30
Sedan - $50
SUV - $100
3. Give a prompt to the customer asking him the type of car
and the number of days he would like to borrow and provide the
fare details to the user.

Created by Febin George


The Four Pillars of OOP in Python 3 for Beginners

EXERCISE - INHERITANCE
Write an object oriented program that performs the following tasks:
1. Create a class called Chair from the base class Furniture
2. Teakwood should be the type of furniture that is used by all furnitures by
default
3. The user can be given an option to change the type of wood used for chair if
he wishes to
4. The number of legs of a chair should be a property that should not be altered
outside the class

Created by Febin George


EXERCISE - POLYMORPHISM

Create a class called Square and perform the following tasks -


(i) Create two objects for this class squareOne and
squareTwo
(ii) Find the result of side of squareOne to the power of side
of squareTwo

Example: If squareOne has length of 2cm each side and


squareTwo has a length of 4cm each side, squareOne **
squareTwo should return 16, which is 2 to the power of 4.

Hint: While performing SquareOne ** SquareTwo, you need to


overload __pow__() method

You might also like