Object-Oriented Programming with Python CS1102
- Subject Code :
CS1102
Python OOPs Assignment
Assignment Questions
Q1. Write a Python program to demonstrate multiple inheritance.
- Employee class has 3 data members Employee ID , Gender (String) , Salary and Performance Rating ( Out of 5 ) of type It has a get() function to get these details from the user.
- Joining Detail class has a data member Date Of Joining of type Date and a function
Get DoJ to get the Date of joining of employees.
- Information Class uses the marks from Employee class and the Date Of Joining date from the Joining Detail class to calculate the top 3 Employees based on their Ratings and then Display, using read Data , all the details on these employees in Ascending order of their Date Of Joining.
Q.2 Write a Python program to demonstrate Polymorphism.
- Class Vehicle with a parameterized function Fare, that takes input value as fare and returns it to calling Objects.
- Createfive separate variables Bus, Car, Train, Truck and Ship that call the Fare
function.
- Usea third variable Total Fare to store the sum of fare for each Vehicle
- Printthe Total
Q3. Consider an ongoing test cricket series. Following are the names of the players and their scores in the test1 and 2.
Test Match 1 :
Dhoni : 56 , Balaji : 94
Test Match 2 :
Balaji : 80 , Dravid : 105
Calculate the highest number of runs scored by an individual cricketer in both of the matches. Create a python function Max_Score (M) that reads a dictionary M that recognizes the player with the highest total score. This function will return ( Top player , Total Score ) . You can consider the Top player as String who is the highest scorer and Top score as Integer .
Input : Max_Score({test1:{Dhoni:56, Balaji : 85}, test2:{Dhoni 87, Balaji:200}}) Output : (Balaji , 200)
Q4. Create a simple Card game in which there are 8 cards which are randomly chosen from a deck. The first card is shown face up. The game asks the player to predict whether the next card in the selection will have a higher or lower value than the currently showing card.
For example, say the card thats shown is a 3. The player chooses higher, and the next card is shown. If that card has a higher value, the player is correct. In this example, if the player had chosen lower, they would have been incorrect. If the player guesses correctly, they get 20 points. If they choose incorrectly, they lose 15 points. If the next card to be turned over has the same value as the previous card, the player is incorrect.
Q5. Create an empty dictionary called Car_0 . Then fill the dictionary with Keys : color , speed
, X_position and Y_position.
car_0 = {'x_position': 10, 'y_position': 72, 'speed': 'medium'} .
- Ifthe speed is slow the coordinates of the X_pos get incremented by
- Ifthe speed is Medium the coordinates of the X_pos gets incremented by 9
- Nowif the speed is Fast the coordinates of the X_pos gets incremented by
Print the modified dictionary.
Q6. Show a basic implementation of abstraction in python using the abstract classes.
- Createan abstract class in
- Implementabstraction with the other classes and base class as abstract
Q7. Create a program in python to demonstrate Polymorphism.
- Makeuse of private and protected members using python name mangling
Q8. Given a list of 50 natural numbers from 1-50. Create a function that will take every element from the list and return the square of each element. Use the python map and filter methods to implement the function on the given list.
Q9. Create a class, Triangle. Its init() method should take self, angle1, angle2, and angle3 as arguments.
Q10. Create a class variable named number_of_sides and set it equal to 3.
Q11. Create a method named check_angles. The sum of a triangle's three angles should return True if the sum is equal to 180, and False otherwise. The method should print whether the angles belong to a triangle or not.
- Write methods to verify if the triangle is an acute triangle or obtuse
- Create an instance of the triangle class and call all the defined
- Create three child classes of triangle class - isosceles triangle, right triangle and
- Define methods which check for their
Q12. Create a class isosceles right triangle which inherits from isosceles triangle and right triangle.
- Define methods which check for their