PP Asmt
PP Asmt
2
Part -A
Write a Python program that defines a class Vehicle with attributes make and model. Create a
subclass Car that inherits from Vehicle and adds a new attribute number_of_doors. Implement
a method to display details of a car.
Define two classes Dog and Cat, both inheriting from a class Animal that has a method speak().
Override the speak() method in both classes so that Dog says "Woof" and Cat says "Meow".
Demonstrate the use of polymorphism by calling the speak() method on instances of both
classes.
Create two classes Person and Employee, where Person has attributes name and age, and
Employee has an attribute employee_id. Create a class Manager that inherits from both Person
and Employee. Write a method to display the manager’s details.
What is inheritance? Explain the concept of multiple & Multilevel inheritance with the help
of suitable example.
Create class called, library with data attributes like Acc-number publisher, title and author,
the methods of the class should include
i) Read ( ) - Acc- number, title, author, publisher.
ii) Compute ( ) - to accept the number of day late, calculate and display
the fine charged at the rate of Rupees 5/- per day.
iii) Display the data
Write user defined exception program in python which will except age as an input from the
user and check whether the user is eligible for voting or not. If age<18 it should raise the
exception as ‘Not eligible for voting’
Write multithread program, where one thread prints square of a number and another thread
prints cube of numbers. Also display the total time taken for execution.
Write a multithreading program, where one thread prints square of a number and another
thread prints factorial of a number. Also display the total time taken for the execution.
write program for Regex to validate-Password, email, URL, Adhar card, PAN Card, Driving
Licence
Part -B
1. Write a MongoDB query to insert a single document into the movies collection with
the following details:
{
"title": "Inception",
"director": "Christopher Nolan",
"year": 2010,
"genres": ["Sci-Fi", "Thriller"],
"rating": 8.8
}
[
{"title": "The Shawshank Redemption", "director": "Frank Darabont", "year": 1994,
"rating": 9.3},
{"title": "The Godfather", "director": "Francis Ford Coppola", "year": 1972,
"rating": 9.2},
{"title": "The Dark Knight", "director": "Christopher Nolan", "year": 2008,
"rating": 9.0}
]
{
"name": "Leonardo DiCaprio",
"dob": "1974-11-11",
"nationality": "American",
"movies": ["Inception", "Titanic", "The Wolf of Wall Street"]
}
4. Write a query to find all documents in the movies collection where the rating is
greater than 8.5.
5. Write a query to retrieve only the title and year fields of all movies directed by
"Christopher Nolan" in the movies collection, excluding the _id field.
6. Write a query to find all movies in the movies collection released between 2000 and
2010, sorted by rating in descending order.
7. How can you find movies in the movies collection that belong to the Sci-Fi genre?
8. Retrieve the first document from the actors collection where the nationality is
"American".
9. Write a query to update the rating of the movie "The Godfather" to 9.4 in the movies
collection.
10. Add a new genre "Crime" to the movie "The Dark Knight" in the movies collection.
11. Write a query to update multiple documents in the movies collection by setting status
to "classic" for all movies released before the year 2000.
12. How would you update the movies field of the actor "Leonardo DiCaprio" in the
actors collection to include a new movie "Once Upon a Time in Hollywood"?
13. Write a query to delete a single document from the movies collection where the title is
"Titanic".
14. How can you delete all movies in the movies collection with a rating less than 5?
15. Write a query to remove the actors collection entirely from the movie database.
16. Delete all documents in the movies collection where the genre includes "Horror".