Python (ME-506) - Important Questions
-
Unit 514 Marks Medium Priority
Explain the differences between multithreading and multiprocessing in Python. Discuss the Global Interpreter Lock (GIL) and its implications for CPU-bound and I/O-bound tasks. Write a complete Python program using the threading module that demonstrates concurrent I/O-bound tasks and then modify the program to use multiprocessing for a CPU-bound computation. Explain why one approach is preferable over the other for each case.
Core concurrency concepts from Unit 5; tests understanding of threading vs multiprocessing and practical implementation.
-
Unit 514 Marks Medium Priority
Write a TCP client-server pair in Python using the socket module to transfer a binary file from client to server. The server should accept connections, receive the file, save it to disk, and send an acknowledgment. Include appropriate exception handling, graceful shutdown, and comments explaining key steps.
Core networking topic in Unit 5; assesses socket programming and file transfer implementation.
-
Unit 510 Marks Medium Priority
Demonstrate how to connect to an SQLite (or MySQL) database from Python. Write code to create a table for student records ($id$, $name$, $marks$), insert multiple records using parameterized queries, update a record, delete a record, and fetch records filtered by a condition. Explain the importance of transactions and how to handle database exceptions.
Core database connectivity topic; tests SQL operations and integration with Python DB-API.
-
Unit 57 Marks Low Priority
Explain Python exception hierarchy and the use of try, except, else, and finally blocks. Define a custom exception class and implement a context manager (using either the class-based protocol or the @contextmanager decorator) that manages a resource safely. Provide code examples.
Exception handling and resource management from Unit 5; tests advanced usage like custom exceptions and context managers.
-
Unit 57 Marks Medium Priority
Describe text and binary file modes in Python. Explain how to perform random access using file.seek() and how to read and write fixed-size records. Demonstrate an efficient method to process a very large text file (several gigabytes) line by line without loading it into memory.
File handling and efficient I/O in Unit 5; emphasizes binary/text modes, random access, and streaming large files.
-
Unit 57 Marks Low Priority
Write regular expressions in Python to validate: (a) an email address of the form local@domain (simple validation), and (b) Indian mobile numbers (10 digits, starting with 6-9). Explain the use of raw strings (r"...") and capturing groups. Provide Python code that uses the re module to find and extract the username and domain from an email.
Regular expressions usage from Unit 5; evaluates pattern design and capturing groups.
-
Unit 514 Marks Medium Priority
Design a GUI application in Python using Tkinter that allows the user to enter student details ($name$, $roll\,no.$, $marks$) and save them into an SQLite database. The GUI should include form validation (e.g., numeric checks for marks), buttons to Add, Update, Delete, and View records, and a list or table widget to display stored records. Provide the complete code and explain how event handling and database interactions are wired together.
GUI programming and integration with backend (database/file) from Unit 5; typical long question in exams.
-
Unit 510 Marks Low Priority
Explain how to perform web scraping in Python using the requests and BeautifulSoup libraries. Write a program that extracts article titles and links from multiple pages of a blog (handle pagination). Discuss how to respect robots.txt, implement polite scraping (rate limiting), and handle common issues like dynamic content and request failures.
Web data acquisition topic from Unit 5; tests practical web scraping and ethical considerations.
-
Unit 57 Marks Low Priority
Write unit tests for a Python function that interacts with an external API to fetch JSON data. Use the unittest framework (or pytest) and demonstrate how to use mocking to replace network calls so tests run offline and deterministically. Provide example test cases and explain the role of setup and teardown methods.
Software testing topic from Unit 5; assesses unit testing skills and mocking external dependencies.
-
Unit 510 Marks Medium Priority
Explain synchronization primitives provided by the threading module: Lock, RLock, Semaphore, Event, and Condition. Implement a producer-consumer problem using a bounded buffer in Python with appropriate synchronization to avoid race conditions and deadlocks. Provide the code and explain how the chosen primitives ensure correctness.
Thread synchronization and inter-thread communication from Unit 5; important for concurrency control questions.
Quick Add to Notes
Save questions, your own notes and screenshots into notes filed by unit. It takes a free account.
Create free accountHave an account? Log in
Notes Panel