0% found this document useful (0 votes)
35 views4 pages

Xii MLL 083 Xi Fila Handling Ms

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views4 pages

Xii MLL 083 Xi Fila Handling Ms

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

DAV INSTITUTIONS, WEST BENGAL ZONE

Minimum Levels of Learning (MLL)


Session 2025-2026
MARKING SCHEME
CLASS: XII SUBJECT: Computer Science
Chapter Name: File Handling
Very Short Answer type / MCQ type questions Marks
1 B 1
2 C 1
3 A 1
4 D 1
5 A 1
6 C 1
7 D 1
8 B 1
9 B 1
10 B 1
Assertion & Reasoning type question Marks
1 C 1
2 D 1
3 C 1
4 A 1
5 A 1
Short answer questions/ Define / Differentiation / Output Type / Lower Order Thinking Marks
Skill (LOTS)
1 Feature Text File Binary File 2
Human-readable, stored in ASCII or Not human-readable, stored in binary
Format
Unicode format
Contains plain text (characters, Contains raw bytes (images, videos,
Content
symbols) executables)
File Usually .exe, .jpg, .mp3, .bin
Usually .txt, .csv, .html etc.
Extension etc.
2 Feature "w" Mode (Write) "a" Mode (Append) 2
Append to a file (create or add to
Purpose Write to a file (create or overwrite)
end)
File Creates file if it doesn't exist; Creates file if it doesn't exist;
Existence overwrites if it does appends if it does
Data Keeps existing content; adds new at
Erases existing content
Handling the end
When you want a fresh file or replace When you want to add to existing
Use Case
content content
3 Feature open() Function with open() Statement 2
Resource Manual (you must close the file using Automatic (automatically
Management file.close()) closes file after block)
Risk of File Not Higher (if an error occurs, file may Lower (ensures file is closed,
Closing remain open) even on error)
Syntax More verbose; requires explicit Cleaner and safer with context
close() managemen
Example using open()
file = open("example.txt", "r")
data = file.read()
file.close() # You must remember to close the file

Example using with open()


with open("example.txt", "r") as file:
data = file.read()
# File is automatically closed here

4 def countwords(): 3
with open("data.txt", "r") as file:
content = file.read()
words = content.split()
print("Total number of words:", len(words))
countwords()
5 def count_vowels(): 3
vowels = "aeiouAEIOU"
count = 0
with open("games.py", "r") as file:
for line in file:
for char in line:
if char in vowels:
count += 1
print("Total number of vowels:", count)

# Call the function


count_vowels()
6 def longline(): 3

with open("quotes.txt", "r") as file:


lines = file.readlines()
if not lines:
print("The file is empty.")
return
longest = max(lines, key=len)
print("The longest line is:")
print(longest.strip())
longline()
7 import pickle 3

def storedata():

for i in range(5):
print(f"\nEnter details for student {i+1}:")
admn = input("Admission Number: ")
name = input("Name: ")
std = input("Class/Standard: ")
section = input("Section: ")

attendance = float(input("Attendance Percentage: "))


student = [admn, name, std, section, attendance]

# Writing the list of students to a binary file


with open("student.bin", "ab") as file:
pickle.dump(student, file)

print("\nData of 10 students has been stored in 'student.bin'.")


storedata()
8 import pickle 3

def readdata():

try:
print("\nStudent Records:")
print("-" * 60)
i=1
file=open("student.bin", "rb")
while True:

student = pickle.load(file)
print(f"Student {i}:")
print(f" Admission Number : {student[0]}")
print(f" Name : {student[1]}")
print(f" Class/Standard : {student[2]}")
print(f" Section : {student[3]}")
print(f" Attendance Percentage: {student[4]}%\n")
i=i+1
a=input()

except FileNotFoundError:
print("The file 'student.bin' does not exist.")
except EOFError:
print("The file is empty.")
file.close()
readdata()
9 import csv 3

def store_employee_data():
n = int(input("Enter number of employees: "))
with open("emp.csv", "w", newline='') as file:
writer = csv.writer(file)

# Write header
writer.writerow(['empid', 'empname', 'desig', 'salary'])

# Write employee data


for i in range(n):
print(f"\nEnter details for employee {i+1}:")
empid = input("Employee ID: ")
empname = input("Employee Name: ")
desig = input("Designation: ")
salary = float(input("Salary: "))
writer.writerow([empid, empname, desig, salary])
print(f"\nData of {n} employees has been stored in 'emp.csv'.")

store_employee_data()
10 import csv 3

def read_employee_data():
with open("emp.csv", "r", newline=''') as file:
reader = csv.reader(file)
header = next(reader, None) # Read the header row

print(header)

for row in reader:


print(row)
read_employee_data()

You might also like