File basics, paths, modes, seek and tell PYQ part 2 — Lecture 25
CBSE | XII CS | Computational Thinking and Programming – 2 | 35 min
You are an expert CBSE XII CS Computer Science teacher, examiner, and study material creator. =========================================== SCOPE — READ BEFORE GENERATING ANYTHING =========================================== Today's lecture covers ONE topic only: "File basics, paths, modes, seek and tell" Lecture number 25 of 91 | Duration: 35 minutes | Board: CBSE Chapter: Computational Thinking and Programming – 2 HARD RULE: Every piece of content you generate — notes, examples, questions, tips — must be directly relevant to "File basics, paths, modes, seek and tell" only. DO NOT pull content, examples, or questions from any other topic or chapter. LECTURE MODE: SUBTOPIC PYQ PRACTICE - Scope: "File basics, paths, modes, seek and tell" only. - Do not reteach the topic from scratch. Use a short recap only when a PYQ needs it. - Main output must be previous-year-question practice: question analysis, marking points, model answers, common mistakes, and timed strategy. - Use the 12 real PYQ record(s) provided below as the source of truth. Do not fabricate board years, marks, or questions. =========================================== SECTION 1: LECTURE INFORMATION =========================================== Class: XII CS | Subject: Computer Science | Board: CBSE Topic: File basics, paths, modes, seek and tell PYQ part 2 Subtopics to cover today: - File basics, paths, modes, seek and tell Student level: Class XII, CBSE Board, average to above-average students preparing for board exams =========================================== SECTION 2: TEACHER'S REFERENCE NOTES =========================================== File basics, paths, modes, seek and tell PYQ part 2 PYQ PRACTICE SCOPE: File basics, paths, modes, seek and tell. Concept ID: U1_FILE_BASICS_MODES. Use only previous-year questions whose concept_ids include U1_FILE_BASICS_MODES. Teaching ideas: Timed PYQ round, board solution, peer marking, and correction of recurring examiner traps. =========================================== SECTION 3: EXAM FREQUENCY DATA (Year-wise) =========================================== Teaching priority: HIGH High-yield concepts: File basics paths modes seek and tell, File basics paths modes seek and tell, Binary file operations with pickle, File basics paths modes seek and tell, CSV file read write and search, File basics paths modes seek and tell, Text file reading writing searching and counting, Text file reading writing searching and counting | Year | Questions | Marks | |------|-----------|-------| | 2021 | 2 | 2 | | 2023 | 2 | 10 | | 2024 | 3 | 9 | | 2025 | 4 | 11 | | 2026 | 1 | 1 | | **Total** | **12** | **33** | =========================================== SECTION 4: ACTUAL PREVIOUS YEAR QUESTIONS (Scope: "File basics, paths, modes, seek and tell" only — 12 questions from board papers) =========================================== PYQ LECTURE RULE: use these questions as the source pool for practice. - This pool has 12 questions: preserve and discuss ALL 12 actual PYQs in Section 7. - Do not compress, replace, paraphrase, or skip any actual PYQ. - Do not create substitute or newly framed questions for this small pool. - Do not fabricate board years, marks, sections, or questions. --- 2021 Board Exam (2 questions | 2 marks) --- Q1. [MCQ] [1M] [Easy] Section-A Syntax for opening Student.csv file in write mode is myfile = open("Student.csv","w",newline=''). What is the importance of newline=''? a) A newline gets added to the file b) Empty string gets appended to the first line. c) Empty string gets appended to all lines. d) EOL translation is suppressed Q2. [MCQ] [1M] [Easy] Section-A Which of the following statement opens a binary file record.bin in write mode and writes data from a list lst1 = [1,2,3,4] on the binary file? a) with open('record.bin','wb') as myfile: pickle.dump(lst1,myfile) b) with open('record.bin','wb') as myfile: pickle.dump(myfile,lst1) c) with open('record.bin','wb+') as myfile: pickle.dump(myfile,lst1) d) with open('record.bin','ab') as myfile: pickle.dump(myfile,lst1) --- 2023 Board Exam (2 questions | 10 marks) --- Q1. [Programming] [5M] [Hard] Section-D (b) Write one point of difference between seek() and tell() functions in file handling. Write a program in Python that defines and calls the following user defined functions : (i) Add_Device() : The function accepts and adds records of the peripheral devices to a csv file 'peripheral.csv'. Each record consists of a list with field elements as P_id, P_name and Price to store peripheral device ID, device name, and price respectively. (ii) Count_Device() : To count and display number of peripheral devices, whose price is less than or equal to 1000. Q2. [Programming] [5M] [Hard] Section-E (i) Differentiate between r+ and w+ file modes in Python. (ii) Consider a file, SPORT.DAT, containing records of the following structure: [SportName, TeamName, No_Players] Write a function, copyData(), that reads contents from the file SPORT.DAT and copies the records with Sport name as "Basket Ball" to the file named BASKET.DAT. The function should return the total number of records copied to the file BASKET.DAT. (ii) A Binary file, CINEMA.DAT has the following structure: {MNO:[MNAME, MTYPE]} Where MNO – Movie Number, MNAME – Movie Name, MTYPE is Movie Type. Write a user defined function, findType(mtype), that accepts mtype as parameter and displays all the records from the binary file CINEMA.DAT, that have the value of Movie Type as mtype. --- 2024 Board Exam (3 questions | 9 marks) --- Q1. [MCQ] [1M] [Easy] Section-A Which of the following file opening mode is used to open a file in append and read mode ? (A) r+ (B) w+ (C) a+ (D) x+ Q2. [Programming] [3M] [Medium] Section-C Write the user defined function Modify() to read a text file "data.txt" and replace all the occurrences of "COmputer" with "Computer" and display all the lines on screen. Q3. [Programming] [5M] [Hard] Section-E (a) (i) What is the main purpose of seek() and tell() method ? (ii) Consider a binary file, Cinema.dat containing information in the following structure : [Mno, Mname, Mtype] Write a function, search_copy(), that reads the content from the file Cinema.dat and copies all the details of the "Comedy" movie type to file named movie.dat. (ii) A Binary file, "Items.dat" has the following structure : [Icode, Description, Price] Where Icode – Item code Description – Detail of item Price – Price of item Write a function Add_data(), that takes Icode, Description and Price from the user and writes the information in the binary file "Items.dat". --- 2025 Board Exam (4 questions | 11 marks) --- Q1. [Assertion-Reason] [1M] [Easy] Section-A Assertion (A): For a binary file opened using 'rb' mode, the pickle.dump() method will display an error. Reason (R): The pickle.dump() method is used to read from a binary file. (A) Both Assertion (A) and Reason (R) are true and Reason (R) is the correct explanation for Assertion (A). (B) Both Assertion (A) and Reason (R) are true and Reason (R) is not the correct explanation for Assertion (A). (C) Assertion (A) is true but Reason (R) is false. (D) Assertion (A) is false but Reason (R) is true. Q2. [Short Answer] [3M] [Medium] Section-C (a) Write a Python function that displays all the lines ending with a dot (.) from a text file, "Colors.txt". For example, if the file "Colors.txt" contains : White is a mix of seven colors. What are these seven colors ? VIBGYOR – violet, indigo, blue, green, orange and red. When we mix all these colors we just get one light which is the WHITE light. Then the output should be : White is a mix of seven colors. VIBGYOR – violet, indigo, blue, green, orange and red. which is the WHITE light. (Hint : You will have to ignore trailing white spaces to check the last character) Q3. [Programming] [3M] [Medium] Section-C A. Write a Python function that displays the number of times the word "Python" appears in a text file named "Prog.txt". Q4. [Programming] [4M] [Medium] Section-E Write a program in Python to create a text file MARKS.TXT and write the names of all those students and their total marks obtained in Physics, Chemistry and Maths whose total marks are greater than 220. --- 2026 Board Exam (1 question | 1 marks) --- Q1. [MCQ] [1M] [Easy] Section-A Consider the statement given below : f1 = open("pqr.dat","_______") Which of the following is the correct file mode to open the file in read only mode ? (A) a (B) rb (C) r+ (D) rb+ =========================================== =========================================== QUESTION PATTERN BANK (What the board actually asks for THIS topic) =========================================== Scope: ONLY questions for today's lecture topic are listed below. DO NOT import questions from other topics or chapters. These are concept-pattern summaries (what TYPE the board asks), not copies of the actual questions — never reproduce full question text here. ### Concept: File basics paths modes seek and tell Pattern: Programming=2, Short Answer=1 | Marks: 3M=2, 4M=1 | Total: 3 questions [Programming] [3M] [Medium] → Core concept of File basics paths modes seek and tell [Short Answer] [3M] [Medium] → Output/result interpretation for the current concept [Programming] [4M] [Medium] → Core concept of File basics paths modes seek and tell ### Concept: File basics paths modes seek and tell, Binary file operations with pickle Pattern: Assertion-Reason=1, MCQ=2, Programming=2 | Marks: 1M=3, 5M=2 | Total: 5 questions [MCQ] [1M] [Easy] × 2 → Core concept of File basics paths modes seek and tell, Binary file operations with pickle [Programming] [5M] [Hard] × 2 → Core concept of File basics paths modes seek and tell, Binary file operations with pickle [Assertion-Reason] [1M] [Easy] → Core concept of File basics paths modes seek and tell, Binary file operations with pickle ### Concept: File basics paths modes seek and tell, CSV file read write and search Pattern: MCQ=1, Programming=1 | Marks: 1M=1, 5M=1 | Total: 2 questions [MCQ] [1M] [Easy] → Exception can occur even when syntax is correct [Programming] [5M] [Hard] → Core concept of File basics paths modes seek and tell, CSV file read write and search ### Concept: File basics paths modes seek and tell, Text file reading writing searching and counting Pattern: MCQ=1 | Marks: 1M=1 | Total: 1 questions [MCQ] [1M] [Easy] → Core concept of File basics paths modes seek and tell, Text file reading writing searching and counting ### Concept: Text file reading writing searching and counting Pattern: Programming=1 | Marks: 3M=1 | Total: 1 questions [Programming] [3M] [Medium] → Core concept of Text file reading writing searching and counting =========================================== =========================================== IMPORTANCE ANALYSIS (allocate teaching time by this ranking) =========================================== | Rank | Concept | Score | Times Tested | Total Marks | Recent Years | Priority | |------|---------|-------|-------------|-------------|--------------|----------| | 1 | File basics paths modes seek and tell, Binary file operations with pickle | 45 | 5 | 13M | 2026, 2025, 2024 | CRITICAL | | 2 | File basics paths modes seek and tell | 30 | 3 | 10M | 2025, 2024 | CRITICAL | | 3 | File basics paths modes seek and tell, CSV file read write and search | 16 | 2 | 6M | 2023, 2021 | HIGH | | 4 | Text file reading writing searching and counting | 12 | 1 | 3M | 2025 | HIGH | | 5 | File basics paths modes seek and tell, Text file reading writing searching and counting | 5 | 1 | 1M | 2024 | MEDIUM | CRITICAL concepts → full sub-section + comparison table + 2 worked examples HIGH concepts → 1 sub-section + 1 worked example MEDIUM concepts → definition + 1 quick example only =========================================== EXAMINER FINGERPRINT — TRAPS TO COVER INTERNALLY =========================================== Use the exam-frequency input and actual previous-year questions to identify traps, marking points, and common mistakes. In this PYQ Practice lecture, actual PYQs may be printed in Section 7 only. Do not print them randomly in concept notes, homework, or unrelated sections. For this lecture, the generated teaching material must strongly cover these traps: No static trap list exists yet for "File basics, paths, modes, seek and tell". Self-generate 4–7 traps from: - actual question patterns for File basics paths modes seek and tell, File basics paths modes seek and tell, Binary file operations with pickle, File basics paths modes seek and tell, CSV file read write and search, File basics paths modes seek and tell, Text file reading writing searching and counting, Text file reading writing searching and counting - common wrong assumptions students make about this concept - output-tracing traps - syntax-vs-runtime traps - comparison traps - order/sequence traps Important: this list should be treated as dynamic — for lectures with no static trap list, generate traps yourself from the categories above rather than leaving this section thin. =========================================== YOUR TASK — Generate a complete classroom-ready teaching package =========================================== Output format: FULL HTML (print-ready, A4, same format as CBSE study material). Use the CSS classes below. NO plain Markdown — use HTML elements only. HTML STRUCTURE TO GENERATE:
CBSE | XII CS | Computational Thinking and Programming – 2 | 35 min