0% found this document useful (0 votes)
0 views3 pages

PP Asmt

The document outlines a programming assignment involving Python and MongoDB, requiring the creation of various classes and methods to demonstrate concepts such as inheritance, polymorphism, operator overloading, and multithreading. It includes tasks for defining classes like Vehicle, Animal, Person, and Library, as well as writing MongoDB queries for inserting, updating, and deleting documents in collections. Additionally, it covers user-defined exceptions and regex validation for various inputs.

Uploaded by

piraj44478
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views3 pages

PP Asmt

The document outlines a programming assignment involving Python and MongoDB, requiring the creation of various classes and methods to demonstrate concepts such as inheritance, polymorphism, operator overloading, and multithreading. It includes tasks for defining classes like Vehicle, Animal, Person, and Library, as well as writing MongoDB queries for inserting, updating, and deleting documents in collections. Additionally, it covers user-defined exceptions and regex validation for various inputs.

Uploaded by

piraj44478
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Assignment No.

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.

Explain operator overloading in Python. Overload the operator +, -, *, <, >


Discuss the polymorphism concept in python create suitable python classes.

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 a program to demonstrate: [4]


i) Creating a Thread without using any class
ii) Creating a Thread by extending Thread class.
Write a program for synchronization of threads using RLOCK. Accept the two numbers from
user and calculate factorial of both numbers simultaneously

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
}

2. Write a query to insert multiple documents into the movies collection:

[
{"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}
]

3. Add a document to the actors collection with the following details:

{
"name": "Leonardo DiCaprio",
"dob": "1974-11-11",
"nationality": "American",
"movies": ["Inception", "Titanic", "The Wolf of Wall Street"]
}

Read Operation Questions

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".

Update Operation Questions

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"?

Delete Operation Questions

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".

You might also like