Python (CS-506) - Important Questions
-
Unit 514 Marks High Priority
Explain how to connect to an SQLite database in Python. Write a complete program to create a table named "students" with columns (id INTEGER PRIMARY KEY, name TEXT, marks REAL), insert at least three records using parameterized queries, fetch and display all records, and demonstrate transaction commit and rollback.
Core practical database CRUD operations and transaction handling in Unit 5 (Database Connectivity).
-
Unit 514 Marks High Priority
Describe and implement a multi-threaded TCP server in Python that can serve multiple clients concurrently. Provide the server code showing socket setup, thread creation for each client connection, client-handling function, and graceful shutdown. Explain the role of the Global Interpreter Lock (GIL) and how it affects I/O-bound vs CPU-bound tasks in this server.
Standard networking + concurrency question combining socket programming and threading (commonly asked in practical/ viva).
-
Unit 510 Marks Medium Priority
Discuss synchronization mechanisms in Python threading. Provide example code using threading.Lock and threading.RLock to protect a shared counter updated by multiple threads. Explain the concept of deadlock, show a small code example that may cause deadlock, and list strategies to avoid deadlock.
Core synchronization concept from Unit 5 (Threading & Concurrency).
-
Unit 510 Marks Medium Priority
Write a Python Flask RESTful API with two endpoints: GET /students to return a JSON list of students and POST /students to add a new student. Show request parsing, basic input validation, error handling, and instructions to run the application.
Web services / REST API fundamentals that link Python back-end programming to Unit 5 practical tasks.
-
Unit 57 Marks High Priority
Explain socket programming for UDP in Python. Write a UDP client-server pair where the client sends a text message and the server receives it, computes the length of the message, and sends the length back to the client. Include code for both client and server.
Fundamental network programming topic (UDP) frequently examined alongside TCP questions in Unit 5.
-
Unit 510 Marks Medium Priority
Design a GUI application using Tkinter that accepts user name and age, displays the entries in a Listbox, and provides Add and Delete buttons. Include event handling, input validation, and use of geometry managers (grid or pack) in your implementation.
GUI development with Tkinter is a practical topic often used for programming tasks in Unit 5.
-
Unit 57 Marks Medium Priority
Explain how to handle database errors and prevent SQL injection in Python database operations. Provide example code that uses parameterized queries, demonstrates exception handling for database errors, and describes input validation techniques.
Security-conscious database programming and error handling are essential Unit 5 concepts for safe applications.
-
Unit 57 Marks Medium Priority
Compare multithreading and multiprocessing in Python. Explain when to choose threading versus multiprocessing. Provide example code showing creation of a child process using multiprocessing.Process and describe basic inter-process communication (IPC) methods.
Concurrency design decision question contrasting two Python parallelism models covered in Unit 5.
-
Unit 57 Marks Medium Priority
Describe how to write unit tests in Python using the unittest module. Write test cases for a function that computes factorial, demonstrating the use of setUp and tearDown methods and asserting expected outcomes, including handling invalid inputs.
Unit testing fundamentals associated with writing reliable Python programs (Unit 5 practical/testing).
-
Unit 57 Marks Low Priority
Explain Python context managers and the semantics of the with statement. Implement a custom context manager class using the enter and exit methods that measures and prints the execution time of a code block.
Language feature question on resource management, relevant for safe I/O and transaction handling in Unit 5.
-
Unit 57 Marks Low Priority
Describe how to perform binary file I/O in Python and demonstrate object serialization using the pickle module. Provide code to serialize a dictionary of student records to a file and then deserialize it back into a Python object.
File I/O and serialization are practical utilities often required in Unit 5 lab tasks.
-
Unit 57 Marks Medium Priority
Discuss logging in Python. Show how to configure the logging module to write messages to a file with a specified format and logging level. Provide sample code that logs INFO and ERROR messages and explain how to use RotatingFileHandler to rotate log files.
Logging is a standard software engineering topic tied to debugging and production readiness of Python programs in Unit 5.
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