Python Excercises For Intermediate
Python Excercises For Intermediate
attributes.
OOP Exercise 2: Create a Vehicle class without any variables and methods
OOP Exercise 3: Create a child class Bus that will inherit all of the variables and
methods of the Vehicle class.
OOP Exercise 4: Class Inheritance. Create a Bus class that inherits from the
Vehicle class. Give the capacity argument of Bus.seating_capacity() a default value
of 50.
OOP Exercise 5: Define property that should have the same value for every class
instance
Define a class attribute”color” with a default value white. I.e., Every Vehicle
should be white.
Note: The bus seating capacity is 50. so the final fare amount should be 5500. You
need to override the fare() method of a Vehicle class in Bus class.
OOP Exercise 7: Determine which class a given Bus object belongs to (Check type of
an object)
OOP Exercise 9: Write a Python class named Student with two attributes student_id,
student_name. Add a new attribute student_class. Create a function to display the
entire attribute and their values in Student class.
OOP Exercise 10: Write a Python class named Student with two instances student1,
student2 and assign given values to the said instances attributes. Print all the
attributes of student1, student2 instances with their values in the given format.
OOP Exercise 13:Write a Python class to get all possible unique subsets from a set
of distinct integers.
Input : [4, 5, 6]
Output : [[], [6], [5], [5, 6], [4], [4, 6], [4, 5], [4, 5, 6]]
OOP Exercise 14: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.
Input: numbers= [10,20,10,40,50,60,70], target=50
Output: 3, 4
Expected output:
2020-02-18
# 2020-03-22 10:00:00
given_date = datetime(2020, 3, 22, 10, 0, 0)
# 2020-02-25
given_date = datetime(2020, 2, 25).date()
# 2020-02-25
date_1 = datetime(2020, 2, 25)
# 2020-09-17
date_2 = datetime(2020, 9, 17)