Xii CS
Xii CS
Xii CS
SCHOOL
Model Test Paper-XII
Subject – Computer Science
MM : 70
General Instructions:
6. Which of the following mode in which we can add data in existing file .
a) a+
b) r+
c) w+
d) None
Section-B
10*2=20
1) Shyam has written a code to input a number and check whether it is prime or not. His
code is having errors. Rewrite the correct code andunderline the corrections made.
def_prime():
m=(input("Enter number to check :: ")
for i in range (2, n//2):
if m% I =0:
print(Number is not prime)
else:
print("Number is prime \n”)
Humpty Dumpty
what you are Up above the world so
high Like a diamond in the sky
5) Rewrite the following code in Python after removing all syntax error(s). Underline each correction done
in the code.
a=10
for i in range(0,p)
If i%2==0:
print (a*4)
else i%5=0:
print (a+3)
else
print(c+10)
7)
Predict the output of the Python code given below:
def div10(n):
if n%10==0:
return n*8
else:
return n+5
def output(m=10):
for i in range(0,m):
print(div10(i),’@’,end=” “)
print(‘\n’)
output(100)
output()
output(25)
Section-C 7*3=21
1)
What will be the output of the following code?
def my_func(var1=100, var2=200):
var1+=10
var2 = var2 – 10
return var1+var2
print(my_func(50),my_func())
2) Create a binary file student.dat to hold students’ records like Rollno., Students name, and Address
using the list. Write functions to write data, read them, and print .
3) def ChangeVal(M,N):
for i in range(N):
if M[i]%5 == 0:
M[i]//=5
if M[i]%3 == 0:
M[i]//=3
L = [25,8,75,12]
ChangeVal(L,4)
for i in L:
print(i,end="#")
5) Write a program to write into file “one.csv” Rollno, Name and Marks separated by comma. It should
have header row and then take in input from the user for all following rows. The format of the file should
be as shown if user enters 2 records.
Roll.No,Name,Marks
20,ronit,67
56,nihir,69
6) Write a user defined function in Python that displays the number of lines starting
with ‘H’ in the filestory.txt.
Eg: if the file contains:
7) Write a user defined function in python that accept a string as a parameter and display
those wordsfrom the string that starts with capital vowel.
Str= “Exam Of Class Twelve”
Section-D 2*5=10
1) Give any one point of difference between a function text and binary file.
Write a Program in Python that defines and calls the following userdefined functions:
(i) add() – To accept and add data of an employee to a CSVfile ‘empdata.csv’. Each record
consists of a list with field elements as eid, ename and eprice to store employee
id, employee name and employee price respectively.
(ii) search()- To display the records of the furniture whose price is more than 10000
Write a Program in Python that defines and calls the following userdefined functions:
(i) 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 to store employee id,
employeename and employee salary respectively.
(ii) COUNTR() – To count the number of records present in the CSVfile named ‘record.csv’.
Section-E 2+2
2. What is the output of the following program if the student.csv file contains following data?
Student.csv
Ronit, 200
Akshaj, 400
Program
import csv
d = csv.reader(“student.csv”)
for row in d:
print (row)