[go: up one dir, main page]

0% found this document useful (0 votes)
170 views2 pages

Python Programming Theory Assignment

Uploaded by

Sourabh Raut
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)
170 views2 pages

Python Programming Theory Assignment

Uploaded by

Sourabh Raut
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

Dr. D. Y.

Patil Unitech Society’s


Dr. D.Y. PATIL INSTITUTE OF MANAGEMENT & RESEARCH
Sant Tukaram Nagar, Pimpri, Pune-411018
Recognized by the Savitribai Phule Pune University (SPPU-IMMP014220) AISHE CODE C-42109

Recipient of the "Best College Award" Accredited by NAAC with "A++ Grade” MBA & MCA Programme Accredited
of Savitribai Phule Pune University (CGPA 3.52) by NBA

MCA-I (Semester-I) A.Y. 2024-25

IT-11: Python Programming

Theory Assignment

Given Date: 24/11/2024 Submission Date:


10/12/2024

Unit -I

1. Write a Python program to find all Armstrong numbers in a given range using loops and
conditionals.
2. Implement a function to check if a given string is a palindrome without using built-in
functions.
3. Write a program to sort a list of dictionaries based on a key (e.g., age in a list of people).
4. Create a frequency counter for characters in a string using dictionaries.
5. Generate a pattern such as Pascal’s Triangle using nested loops.
6. Write a program to find the union, intersection, and difference between two sets.

Unit -II

1. Implement a nested function that calculates compound interest using non-local variables.
2. Write a program using lambda to filter even numbers from a list.
3. Create a generator function to yield Fibonacci numbers up to a certain limit.
4. Develop a custom Python module with functions for basic statistical operations (mean,
median, mode).
5. Write a program to handle file reading errors and log them to a separate file.
6. Create a custom exception class AgeException and use it to validate user input.
Unit III

1. Implement a class BankAccount with methods for deposit, withdrawal, and displaying
the account balance.
2. Develop a hierarchy of shapes (e.g., Shape, Circle, Rectangle) with area and perimeter
methods.
3. Overload the + operator for concatenating two custom string objects.
4. Create a static method to validate user credentials (e.g., email format, password length).
5. Implement a class Library containing a list of Book objects.
6. Demonstrate method overriding in a superclass-subclass relationship for a payment
system (e.g., Payment, CardPayment).
7. Write a program to validate a password that meets certain criteria (length, uppercase,
digit, special character).
8. Parse email addresses from a given text and classify them by domain.
9. Create threads to perform independent tasks such as downloading multiple files
simultaneously.
10. Write a Python program to create two threads. The first thread will print even numbers,
and the second thread will print odd numbers. Demonstrate the concept of multithreading.
11. Use multithreading to compute factorials of multiple numbers and log the results into a
file.

Unit IV

1. Develop a Python program to create, read, update, and delete documents in a MongoDB
collection.
2. Write a program to insert valid data into MongoDB using exception handling for errors.
3. Use MongoDB’s aggregation pipeline to find the average salary of employees in a
collection.

Unit V

1. Create a Django project with models for Product and Category, along with views to
display them on a webpage.
2. Implement user login, logout, and registration functionality in a Django application.
3. Build a REST API for a task management system where users can create, update, and
delete tasks.

Common questions

Powered by AI

MongoDB's aggregation pipeline can be used to compute the average salary of employees by utilizing stages such as $group and $avg. First, group the documents by a unique identifier, or use a base group to aggregate all salaries. Then apply the $avg operator to compute the average salary over the specified fields, which efficiently processes large datasets and provides optimized performance .

Handling file I/O errors and logging them to a separate file offers several advantages, including improved debugging and tracking of file operation failures without interrupting the program's flow. It provides a persistent record for developers to analyze and fix recurring issues, increasing the robustness and user experience of the application .

Nested functions in Python are functions defined within other functions. They can capture and store the state of their enclosing scope using non-local variables, allowing for advanced closure usage. In the calculation of compound interest, you can use a nested function to update the principal with interest and keep track of internal variables between calls. This method can encapsulate state, promoting organized and reusable financial logic .

Using a custom exception class like AgeException allows for more precise error handling and readability in a program. This specific exception can be raised when a certain condition, such as an invalid age input, is met. It also helps in distinguishing different types of errors easily, improving debugging and maintaining a clean codebase .

Multithreading can significantly enhance the performance of a Python program, especially with I/O operations such as file handling and network operations, which are naturally latency bound. Threads allow concurrent execution, meaning that the program can handle multiple operations simultaneously. For instance, downloading files can be split across threads, allowing network latency to overlap and not stall program execution .

You can use a lambda function to filter even numbers in a list by combining it with the filter() method. Define a lambda that returns True if a number is even (i.e., number % 2 == 0) and pass this lambda to filter() along with the list. This technique provides a concise way to process collections without explicitly writing a separate function .

Operator overloading in Python allows you to redefine the behavior of operators for user-defined classes. For concatenating two custom string objects, you override the __add__ method in your class definition. By returning a new object that combines the strings from both objects, you can control how the '+' operator interacts with instances of your custom class .

To implement a function that checks if a string is a palindrome without using built-in functions, you need to manually compare the characters. Begin by iterating over the string up to its midpoint, comparing each character with its corresponding character from the end of the string. If all characters match, the string is a palindrome; otherwise, it is not .

In a Django application, user authentication features like login and registration can be managed using Django's built-in authentication system. It includes creating User models and forms for collecting user credentials. The auth system provides decorators and helpers to manage user sessions and permissions. During registration, store hashed passwords and ensure that session management is secured to protect user data .

To develop a REST API for a task management system in Django, start by setting up Django REST Framework. Define models for tasks and users, create serializers to translate model instances into JSON, and views to handle CRUD operations. Utilize Django's URL routing to route API requests to the appropriate view. Implement authentication and permissions to handle user-specific data securely .

You might also like