Class 12 Computer Science 083 – Important Programming Questions on (Functions, File Handling, Exceptions, Stacks & Python MySQL)
This post contains the most important Class 12 Computer Science (083) Python programming questions based on Functions, File Handling, Exception Handling, Stacks, and Python MySQL Connectivity. These questions are highly useful for CBSE Board Exam preparation, practical files, viva, and Python programming practice.
The questions are designed to improve logic building, problem-solving skills, and concept clarity. Students are advised to practice each program, run it in Python, and try variations to strengthen understanding.
Functions — Important Programming Questions (Class 12)
Functions in Python help in modular programming and code reusability. These questions test concepts such as parameters, return values, recursion, local & global variables, and logical function-based programs.
Sample Questions:
| S. No. | Questions | View Solution | Watch Explanation |
|---|---|---|---|
| 1 | Write a function dispBook(BOOKS) in Python, that takes a dictionary BOOKS as an argument and displays the names in uppercase of those books whose name starts with a consonant. For example, Consider the following dictionary: BOOKS = {1 : “Python”, 2 : “Internet Fundamentals “, 3 :”Networking”, 4 : “Oracle sets”, 5 : “Understanding HTML”} The output should be: PYTHON NETWORKING | 🔗View Solution | 🎥Watch Explanation |
| 2 | Write a Python Program containing a function FindWord(STRING, SEARCH), that accepts two arguments : STRING and SEARCH, and prints the count of occurrences of SEARCH in STRING. Write appropriate statements to call the function. For example, if STRING = “Learning history helps to know about history with an interest in history” and SEARCH = ‘history’, The function should display: The word history occurs 3 times. | 🔗View Solution | 🎥Watch Explanation |
| 3 | Write a function Show_sal(EMP) in python that takes the dictionary, EMP as an argument. Display the salary if it is less than 25000. Consider the following dictionary EMP = {1 : 18000, 2 : 25000, 3 : 28000, 4 : 15000} The output should be: 18000 15000 | 🔗View Solution | 🎥Watch Explanation |
👉 View More Functions Questions — Full List
Text File Handling — Python Programs
These questions help students understand reading, writing, searching, and processing data in Text files using Python.
Sample Questions: Text File Handling
| S. No. | Questions | View Solution | Watch Explanation |
|---|---|---|---|
| 1 | Write a function COUNT() in Python to read from a text file ‘Gratitude.txt’ and display the count of the letter ‘e’ in each line. Example: If the file content is as follows: Gratitude is a humble heart’s radiant glow, A timeless gift that nurtures and bestows. It’s the appreciation for the love we’re shown, In moments big and small, it’s truly known. The COUNT() function should display the output as: Line 1 : 3 Line 2 : 4 Line 3 : 6 Line 4 : 1 | 🔗View Solution | 🎥Watch Explanation |
| 2 | Write a function Start_with_I() in Python, which should read a text file ‘Gratitude.txt’ and then display lines starting with ‘I’. Example: If the file content is as follows: Gratitude is a humble heart’s radiant glow, A timeless gift that nurtures and bestows. It’s the appreciation for the love we’re shown, In moments big and small, it’s truly known. Then the output should be It’s the appreciation for the love we’re shown, In moments big and small, it’s truly known. | 🔗View Solution | 🎥Watch Explanation |
| 3 | Write a function in Python to read a text file, Rhyme.txt and displays those words which have length more than 5. | 🔗View Solution | 🎥Watch Explanation |
👉 View More File Handling Questions — Full List
Binary File Handling — Python Programs
These questions help students understand reading, writing, searching, and processing data in Binary files using Python.
Sample Questions: Binary File Handling
| S. No. | Questions | View Solution | Watch Explanation |
|---|---|---|---|
| 1 | Consider a binary file ‘INVENTORY.DAT’ that stores information about products using tuple with the structure (ProductID, ProductName, Quantity, Price). Write a Python function expensiveProducts() to read the contents of ‘INVENTORY.DAT’ and display details of products with a price higher than Rs. 1000. Additionally, calculate and display the total count of such expensive products. For example: If the file stores the following data in binary format: (1, ‘ABC’, 100, 5000) (2, ‘DEF’, 250, 1000) (3, ‘GHI’, 300, 2000) Then the function should display (1, ‘ABC’, 100, 5000) (3, ‘GHI’, 300, 2000) Total expensive products: 2 | 🔗View Solution | 🎥Watch Explanation |
| 2 | Consider a file FLIGHT.DAT containing multiple records. The structure of each record is as shown below: [Fno, FName, Fare, Source, Destination] Write a function COPY_REC() in Python that copies all those records from FLIGHT.DAT where the source is DELHI and the destination is MUMBAI, into a new file RECORD.DAT | 🔗View Solution | 🎥Watch Explanation |
| 3 | Consider a Binary file BOOK.DAT containing a dictionary having multiple elements. Each element is in the form. BNO:[BNAME,BTYPE,PRICE] as key:value pair where BNO – Book Number BNAME – Book Name BTYPE – Book Type PRICE – Book price Write a user-defined function, findBook(price), that accepts price as parameter and displays all those records from the binary file BOOK.DAT which has a book price more than or equal to the price value passed as a parameter. | 🔗View Solution | 🎥Watch Explanation |
👉 View More File Handling Questions — Full List
CSV File Handling — Python Programs
These questions help students understand reading, writing, searching, and processing data in CSV files using Python.
Sample Questions: CSV File Handling
| S. No. | Questions | View Solution | Watch Explanation |
|---|---|---|---|
| 1 | Mandeep is a Python programmer working in C-company. For storing details of employees working in the company, he has created a csv file named record.csv, to store the The structure of record.csv is : [Emp_Id, Emp_Name, Mobile, Salary] Where Emp_Id is Employee ID (integer) Emp_Name is Employee Name (string) Mobile is to store mobile number of employee (integer) Salary – Salary earned by the employees(integer) Mandeep want to write program in Python that defines and calls the following user defined functions: (a) ADD() – To accept and add data of an employee to a CSV file ‘record.csv’. Each record consists of a list with field elements as empid, name and mobile andemployee salary respectively. (b) COUNTR() – To count the number of records present in the CSV file named ‘record.csv’. As python expert help him complete the task | 🔗View Solution | 🎥Watch Explanation |
| 2 | Write a Program in Python that defines and calls the following user defined functions: (i) add() – To accept and add data of a product to a CSV file ‘product.csv’. Each record consists of a list with elements as pid, pnameand priceto storeproduct id, product name and pricerespectively. (ii) search()- To display the records of the products whose price is more than5000. | 🔗View Solution | 🎥Watch Explanation |
| 3 | Write a Program in Python that defines and calls the following user defined functions: (i) INSERT() – To accept and add data of a student to a CSV file ‘student.csv’. Each record consists of a list with field elements as sid, name and marksto store student id, name and marks respectively. (ii) COUNTSTUDENTS() – To count the number of records present in theCSV file named‘student.csv’. | 🔗View Solution | 🎥Watch Explanation |
👉 View More File Handling Questions — Full List
Stacks Using List — Python Programs
Overview:
These programs focus on push, pop, peek, traversal, and menu-driven stack operations using Python lists.
Sample Questions: Stack using List – Python Programs
| S. No. | Questions | View Solution | Watch Explanation |
|---|---|---|---|
| 1 | Given a Dictionary Stu_dict containing marks of students for three test-series in the form Stu_ID:(TS1, TS2, TS3) as key-value pairs. Write a Python program with the following user-defined functions to perform the specified operations on a stack named Stu_Stk (i) Push_elements(Stu_Stk, Stu_dict) : It allows pushing IDs of those students, from the dictionary Stu_dict into the stack Stu_Stk, who have scored more than or equal to 80 marks in the TS3 Test. (ii) Pop_elements(Stu_Stk): It removes all elements present inside the stack in LIFO order and prints them. Also, the function displays ‘Stack Empty’ when there are no elements in the stack. Call both functions to execute queries. For example: If the dictionary Stu_dict contains the following data: Stu_dict ={5: (87,68,89), 10:(57,54,61), 12:(71,67,90), 14:(66,81,80), 18:(80,48,91)} After executing Push_elements(), Stk_ID should contain [5,12,14,18] After executing Pop_elements(), The output should be: 18 14 12 5 Stack Empty | 🔗View Solution | 🎥Watch Explanation |
| 2 | Write a function in Python, Push(Cosmetics) where, Cosmetic is a dictionary containing the details of products– {Pname:price}. The function should push the names of those products in the stack whose price is greater than 130. Also display the count of elements pushed into the stack. For example: If the dictionary contains the following data: Ditem = {“FaceWash”:105, “Facepack”:150, “CleansingMilk”:130, “Sunscreen”: 180, “FaceMask”:115} The stack should contain Facepack Sunscreen The output should be: The count of elements in the stack is 2 | 🔗View Solution | 🎥Watch Explanation |
| 3 | A list named as Record contains following format of for students: [student_name, class, city]. Write the following user defined functions to perform given operations on the stack named ‘Record’: (i) Push_record(Record) – To pass the list Record = [ [‘Rahul’, 12,’Delhi’], [‘Kohli’,11,’Mumbai’], [‘Rohit’,12,’Delhi’] ] and then Push an object containing Student name, Class and City of student belongs to ‘Delhi’ to the stack Record and display and return the contents of stack (ii) Pop_record(Record) – To pass following Record [[“Rohit”,”12”,”Delhi”] [“Rahul”, 12,”Delhi”] ] and then to Pop all the objects from the stack and at last display “Stack Empty” when there is no student record in the stack. Thus the output should be: – [“Rohit”,”12”,”Delhi”] [“Rahul”, 12,”Delhi”] Stack Empty | 🔗View Solution | 🎥Watch Explanation |
👉 View More Stack Programs — Full List
Python MySQL Connectivity — Important Programming Questions
Overview:
These questions help students practice database connectivity, CRUD operations, and menu-driven DB programs using Python and MySQL.
Sample Questions: Python MySQL Connectivity
| S. No. | Questions | View Solution | Watch Explanation |
|---|---|---|---|
| 1 | Saritha has created a table Inventory in MYSQL database, warehouse: Inv_No(Inventory Number )- integer Inv_name(Name) – string Inv_Entry(Date ) Inv_price – Decimal Note the following to establish connectivity between Python and MySQL: Username – root Password – 12345 Host – localhost Saritha, now wants to delete the records of inventory whose price is more than 1000. Help Saritha to write the program in Python. | 🔗View Solution | 🎥Watch Explanation |
| 2 | Kavya wants to write a program in Python to insert the following record in the table named Inventory in MYSQL database, WAREHOUSE: Inv_No(Inventory Number ) – integer Inv_name(Name) – string Inv_Entry(Date ) Inv_price – Decimal Note the following to establish connectivity between Python andMySQL: Username – root Password – 12345 Host – localhost The values of fields Inv_No, Inv_name,Inv_Entryand Inv_price has to be accepted from the user. Help Kavya to write the program in Python. | 🔗View Solution | 🎥Watch Explanation |
| 3 | Virat has created a table named TRAVELS in MySQL: Tour_ID – string Destination – String Geo_Cond– String Distance – integer (In KM) Note the following to establish connectivity between Python and MYSQL: ∙ Username is root ∙ Password is bharat ∙ The table TRAVELS exists in a MYSQL database named TOUR. ∙ The details Tour_ID, Destination, Geo_Cond and Distance are to be accepted from the user. Virat wants to display All Records of TRAVELS relation whose Geographical condition is hilly area and distance less than 1000 KM. Help Virat to write program in python. | 🔗View Solution | 🎥Watch Explanation |
👉 View More Python MySQL Programs — Full List
How to Practice These Questions (Short Guide)
Students should:
- Try writing programs without seeing solutions
- Run and test programs in Python IDE
- Modify logic to create variations
- Practice for viva and practical exam
- Focus on logic, not memorization
Benefits of Practicing These Programs (Bullet List)
- Improves Python logic building
- Strengthens CBSE board exam preparation
- Enhances practical file and viva performance
- Builds programming confidence
- Covers most-asked exam-oriented programs
Conclusion
These Class 12 Computer Science important programming questions will help students build strong Python concepts and score better in exams. Bookmark this page and keep practicing regularly.
👉 More topic-wise questions are available in the linked pages above.







