Exercises With Solutions On OOP
Exercises With Solutions On OOP
https://pynative.com/python-object-oriented-programming-oop-exercise/
https://anandology.com/python-practice-book/object_oriented_programming.html
https://hub-courses.pages.pasteur.fr/python-solutions/
Object_Oriented_Programming.html
https://www.rithmschool.com/courses/python-fundamentals-part-2/python-object-
oriented-programming-exercises
https://gist.github.com/KirosG/f265f136bd97bd669632fa0f2f2721b4
https://pynative.com/python/object-oriented-programming/
def __init__(self,a,b,r):
self.a = a
self.b = b
self.r = r
2 - Define a Area() method of the class which calculates the area of the circle.
3 - Define a Perimeter() method of the class which allows you to calculate the perimeter of
the circle.
4 - Define a testBelongs() method of the class which allows to test whether a point A(x,
y) belongs to the circle C(O, r) or not.
1. Define a Book class with the following attributes: Title, Author (Full name), Price.
2. Define a constructor used to initialize the attributes of the method with values
entered by the user.
3. Set the View() method to display information for the current book.
4. Write a program to testing the Book class.
1- Create a class called TK_extended which inherits from TK class and having the attributes:
- Master: that represents the name of the main window
- title: that represents the title of the main window
2 - Create a method called create() that creates the window
3 - Create a method called resize(width, height) that can resize the window.
4 - Create a method called generate() to generate the window
[An editor is available at the bottom of the page to write and execute the
scripts.]
1. Write a Python program to import built-in array module and display the
namespace of the said module. Go to the editor
2. Write a Python program to create a class and display the namespace of the
said class. Go to the editor
7. Write a simple Python class named Student and display its type. Also,
display the __dict__ attribute keys and the value of the __module__ attribute
of the Student class. Go to the editor
8. Write a Python program to crate two empty classes, Student and Marks.
Now create some instances and check whether they are instances of the said
classes or not. Also, check whether the said classes are subclasses of the
built-in object class or not. Go to the editor
3. Write a Python class to find validity of a string of parentheses, '(', ')', '{', '}', '['
and ']. These brackets must be close in the correct order, for example "()" and
"()[]{}" are valid but "[)", "({[)]" and "{{{" are invalid. Go to the editor
4. Write a Python class to get all possible unique subsets from a set of distinct
integers. Go to the editor
Input : [4, 5, 6]
Output : [[], [6], [5], [5, 6], [4], [4, 6], [4, 5], [4, 5, 6]]
Click me to see the solution
5. Write a Python class to find a pair of elements (indices of the two numbers)
from a given array whose sum equals a specific target number.
Note: There will be one solution for each input and do not use the same
element twice. Go to the editor
Input: numbers= [10,20,10,40,50,60,70], target=50
Output: 3, 4
6. Write a Python class to find the three elements that sum to zero from a set
of n real numbers. Go to the editor
Input array : [-25, -10, -7, -3, 2, 4, 8, 10]
Output : [[-10, 2, 8], [-7, -3, 10]]
9. Write a Python class which has two methods get_String and print_String.
get_String accept a string from the user and print_String print the string in
upper case. Go to the editor
Click me to see the solution