CBSE 2026-27 · Class 12 · Code 083

Important CS Programs

Master your practical exams with our curated list of essential Python programs for Class 12 Computer Science. Click on any program to view the code, copy it, or run it instantly.

In each topic the programs go from Easy to Hard. A CBSE tag shows the paper or practical list a program comes from; Rare marks less common programs that are still in the syllabus.

91 programs in 7 topics

FUNCTIONS 21 programs

  1. Write a function once and call it as many times as you need, with a different argument each time.

    Easy
  2. return sends the answer back to the caller, which can store it or print it.

    Easy
  3. A function can return several values; Python packs them into a tuple.

    Easy
  4. Default values are used when an argument is left out; keyword arguments can be given in any order.

    Easy
  5. Take a list of words and return a new list with each word capitalized.

  6. Print the sum of only the positive numbers in a list.

  7. A random number generator that gives numbers from 1 to 6, like rolling a dice.

  8. A variable made inside a function is local. Use the global keyword to change a global variable.

    Medium
  9. A list passed to a function can be changed inside it; an integer cannot.

    Medium
  10. The corrected code of an error-finding question: return the reverse of a number.

  11. The corrected code of an error-finding question: return the number of vowels in a string.

  12. Return a tuple with the length of each word of a string.

  13. Take a dictionary of places and display, in uppercase, the names longer than 5 characters.

  14. A dictionary holds Name: [Eng, Math, Science]. Display each student's grade: A (90+), B (60-89), C (below 60).

  15. Return the word with every Nth letter replaced by an underscore.

  16. Count the pairs (a, b) in a tuple of pairs where both a and b are even.

  17. Remove n from the list if it is there; otherwise print "Element not found".

  18. A tuple cannot be changed, so build a new tuple with the first and last elements swapped.

  19. Return a dictionary showing how many times each word appears in a sentence.

    Hard Rare
  20. is_armstrong() checks one number; armstrong_in_range() uses it to find all of them in a range.

    Hard Rare
  21. Two words are anagrams if they use the same letters, e.g. LISTEN and SILENT.

    Hard Rare

EXCEPTION HANDLING 7 programs

  1. try runs the risky code; except catches the error so the program does not crash.

    Easy
  2. int() raises ValueError when the input is not a whole number.

    Easy
  3. Catch different errors separately and show a suitable message for each.

    Medium
  4. else runs only when there is no error; finally always runs.

    Medium
  5. Use raise to report wrong data yourself, then catch it with except.

    Medium
  6. A while loop with try-except asks again and again until a proper number is entered.

    Hard Rare
  7. Opening a file that does not exist in read mode raises FileNotFoundError.

    Hard Rare

TEXT FILES 21 programs

  1. Mode "w" creates the file (or empties it); mode "r" reads it.

    Easy
  2. Mode "a" adds to the end of the file; with closes the file by itself.

    Easy
  3. read() gives a string, readline() gives one line, readlines() gives a list of lines.

    Easy
  4. Count the lines, words and characters in a text file.

    Easy
  5. tell() gives the position of the file pointer; seek() moves it.

    Easy
  6. Read a text file line by line and display each word separated by a #.

  7. Read a text file and display the number of vowels, consonants, uppercase and lowercase characters.

  8. Read Alpha.txt and display the lines that begin with the word You.

  9. Display how many times the word Python appears in Prog.txt.

  10. Display the lines of Elections.txt that contain the word vote.

  11. Display the lines of Colors.txt that end with a dot (.).

  12. Display the lines of a text file that do not start with a vowel.

  13. Count and return the number of digits in the text file Space.txt.

  14. Display the words in which the lowercase letter e appears at least twice.

  15. Remove all the lines that contain the character a and write them to another file.

  16. Display the words that start and end with a vowel, separated by a space.

  17. Display the lines that contain a four-digit year such as 1999 or 2024.

  18. Display the line that has the maximum number of vowels.

  19. A sentence ends with . ? or ! - display every sentence of STORY.TXT on a separate line.

  20. Copy a file line by line, replacing one word with another.

    Hard Rare
  21. Find and display the longest word in a text file.

    Hard Rare

BINARY FILES (PICKLE) 12 programs

  1. pickle.dump() writes a Python object to a binary file; pickle.load() reads it back.

    Easy
  2. Each dump() writes one record; read until EOFError to get all of them.

    Easy
  3. Read records one by one and count them.

    Easy
  4. Create a binary file with name and roll number. Search for a roll number and display the name, or a message if it is not found.

  5. EMP.DAT stores [Emp_Id, Name, Salary]. Display the employees whose salary is below 25000.

  6. items.dat stores {item_id: [item_name, amount]}. Copy the records with amount greater than 1000 to new_items.dat.

  7. SPORT.DAT stores [SportName, TeamName, No_Players]. Copy the Basket Ball records to BASKET.DAT and return how many were copied.

  8. CINEMA.DAT stores {MNO: [MNAME, MTYPE]}. Display the records whose movie type is mtype.

  9. DOCTORS.DAT stores [D_ID, D_Name, D_Dept, Experience]. Write a function to add a doctor and one to display all records.

  10. Create a binary file with roll number, name and marks. Input a roll number and update the marks.

  11. RESOURCES.DAT stores (R_ID, R_Name, R_Expertise, Charges). Append() adds a record; Update() increases every charge by 500.

  12. Keep every record except the one to delete, then write the file again.

    Hard Rare

CSV FILES 11 programs

  1. csv.writer() writes lists as comma-separated rows. Use newline="" to avoid blank lines.

    Easy
  2. writerows() takes a list of rows and writes all of them.

    Easy
  3. csv.reader() gives each row as a list of strings.

    Easy
  4. next() reads the header row so that only the data rows are processed.

    Medium
  5. Create a CSV file of user-ids and passwords, then search the password for a given user-id.

  6. Peripheral.csv stores [P_id, P_name, Price]. Add_Device() adds a record; Count_Device() counts devices priced below 1000.

  7. Result.csv stores [St_Id, St_Name, Game_Name, Result]. Accept() adds a record (with headings on top); wonCount() counts the students who won.

  8. CLUB.CSV stores [Mno, Name, Mobile, Fee]. NewMembers() adds records; PriorityMember() shows members paying more than 35000.

  9. Rentals.csv stores Vehicle_ID, Vehicle_Type, Hours_Rented, Rate_Per_Hour. Add a rental and calculate the total rent (hours x rate).

  10. States.csv stores [State, Capital, Population, Language]. Skip the header and append the records with population above 10000000 to More.csv.

  11. Read all the rows into a list, change the one you need, then write the file again.

    Hard Rare

DATA STRUCTURE (STACK) 10 programs

  1. A stack is LIFO: the last item pushed is the first popped. append() pushes, pop() pops.

    Easy
  2. Check for an empty stack, look at the top item, and display from top to bottom.

    Easy
  3. Implement a stack using a list, with a menu to push, pop, peek and display.

  4. Push the numbers of Nums that have 5 or more digits, then pop and display them, then "Stack Empty".

  5. NList holds [City, Country, Distance]. Push [City, Country] for cities not in India and less than 3500 km from Delhi, then pop them.

  6. Push the (title, price) records with price above 250 to the stack Books, then pop and display them.

  7. Accept 10 integers, push the 3-digit even ones to a stack, then pop and display them all.

  8. Push every character, then pop them all: they come out in reverse order.

    Hard Rare
  9. Push the remainders of division by 2, then pop them to get the binary number.

    Hard Rare
  10. Push each opening bracket and pop when its closing bracket comes. Balanced if the stack ends empty.

    Hard Rare

PYTHON-MYSQL CONNECTIVITY 9 programs

  1. Connect with mysql.connector and check the connection. Needs MySQL and mysql-connector-python on your computer.

    Easy
  2. Run SQL with cursor.execute(). Changes (INSERT, UPDATE, DELETE) need commit().

    Medium
  3. Display all the details from the table flight in the database Travel (user root, password airplane).

  4. Display the records from the table Account in the database SCHOOL whose fees is less than 5000.

  5. Accept rno, name, DOB and fee and insert them into the table Student in the database SCHOOL.

  6. In the database Keeper, set Qty to 20 for item code 111 in the table shop.

  7. In the database LibraryDB, change the Book_Title to Data Structures in Python for Book_ID 109.

  8. fetchone() gives one row at a time (None at the end); rowcount tells how many rows were read.

    Hard Rare
  9. Pass values separately with %s; the connector puts them into the query safely.

    Hard Rare