1st Half(Bcs) Ans

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

CLASS : XII (BCS) HALF REVISION-I TIME: 3 HRS

DATE : 7.12.2024 COMPUTER SCIENCE (083) MARKS : 70

General Instructions:
This question paper contains 37 questions.
● All questions are compulsory.
● The paper is divided into 5 Sections- A, B, C, D and E.
● Section A consists of 21 questions (1 to 21). Each question carries 1 Mark.
● Section B consists of 7 questions (22 to 28). Each question carries 2 Marks.
● Section C consists of 3 questions (29 to 31). Each question carries 3 Marks.
● Section D consists of 4 questions (32 to 35). Each question carries 4 Marks.
● Section E consists of 2 questions (36 to 37). Each question carries 5 Marks.
● All programming questions are to be answered using Python Language only.
● In case of MCQ, text of the correct answer should also be written.

SECTION - A (30 MINS)(21*1 = 21 MARKS)

1. What will be the result of following expression:


10>12 and “a”+1<55
a) True b) False c) Error d) None
2. What will be the output of the following statement:
print(30/5+(16+6))
a) 26.0 b) 28.0 c) 25.0 d) 32.0
3. Which of the following statement(s) would give an error after executing the following code?
x=50 # Statement 1
Def func(x) # Statement 2
x=2 # Statement 3
func(x) # Statement 4
print(x) # Statement 5
a) Statement 1 b) Statement 3 & 4 c) statement 4 d) Statement 2
4. State true or false: While defining a function in python, the positional parameters in the function header must
always be written after the default parameter. F
5. Write the output for the following python snippet.
LST=[1,2,3,4,5,6]
for i in range(6):
LST[i-1]=LST[i]
print(LST) output: [2, 3, 4, 5, 1, 1]
6. Python Dictionary is used to store the data in a _______ format.
a) key value pair b) group value pair c) select value pair d) none of these
7 . Evaluate the following expression.
A=12//5+5//7+8-2+4//2
a) 1 b) 8 c) 5 d) 10
8.State true or false. “ Immutable data type are those that can never change their values “ .T
9 . Select the options that print
hello-how-are-you
a) print(‘hello’, ‘how’, ‘are’, ‘you’) b) print(‘hello’, ‘how’, ‘are’, ‘you’ + ‘-‘ * 4)
c) print(‘hello-‘ + ‘how-are-you’) d) print(‘hello’ + ‘-‘ + ‘how’ + ‘-‘ + ‘are’ + ‘you’)
10. What will be the output of the following python code:
def A_func (x=10, y=20):
x =x+1
y=y-2
return (x+y)
print(A_func(5),A_func())
a) 24,29 b) 15,20 c) 20,30 d) 25,30
11. Which of the following functions is a built-in function in python?
a) seed() b) sqrt() c) factorial() d) print()
12. What is the output of the expression? round(4.5676,2)?
a) 4.5 b) 4.6 c) 4.57 d) 4.56
13. Which of the following commands can be used to read "n" number of characters from a file using the file
object <File>?
a) File.read(n) b) N = file.read() c) File.readline(n) d) File.readlines()
14. Give the output of the following
x=3
x+=x-x
print(x)
a) 3 b) 1 c) 2 d) 0
15. Given the following dictionaries
dict_exam={"Exam":"AISSCE", "Year":2023}
dict_result={"Total":500, "Pass_Marks":165}
Which statement will merge the contents of both dictionaries?
a) dict_exam.update(dict_result)
b) dict_exam + dict_result
c) dict_exam.add(dict_result)
d) dict_exam.merge(dict_result)
16. This method is used to load (unpickling) data from binary file
a) load() b) dump() c) seek() d) tell()
17. Find the invalid Identifier from the following:
a)Myname b) 1Myname c) My_name d) Myname2
18. In a Python program, a control structure:
a) Defines program-specific data structre
b) Directs the order of Execution of statements in the program
c) Dictates what happens before the program starts and after it terminates
d) None of above
19. The syntax of seek() is : file object.seek(offset[,reference_point])
What is the default value of reference point ?
a) 0 b) 1 c) 2 d) 3
20. Assertion (A): Inside a function if we make changes in a string it will reflect back to the original string.
Reason (R): String is an immutable datatype and it is called by value. (d)
21. Assertion (A): In CSV file there is a blank line after every record.
Reason (R): Default value of newline is ‘\n’ in open() statement used with csv file. (a)
(a) A and R are True and R is correct explanation of A.
(b) A and R are True and R is not correct explanation of A.
(c) A is True but R is False.
(d) A is False but R is True.
SECTION- B (30 MINS)(7*2 = 14 MARKS)
22. Following code is having some errors. Rewrite the code after correcting and underlining each correction:
x == 20
def printme():
y = x + 10
sum = 0
for i in range(x,y)
if i%3=0:
sum=sum+i+1
Elseif:
sum += 2
return(sum)
Answer:
x = 20
def printme():
y = x + 10
sum = 0
for i in range(x,y):
if i%3==0:
sum=sum+i+1
elif:
sum += 2
return(sum)
23. Write Output:
colors=["violet", "indigo", "blue", "green", "yellow", "orange", "red"]
del colors[4]
colors.remove("blue")
colors.pop(3)
print(colors)
Ans:violet,indigo,green,red
24. Predict the output of the following code
def Alter(M,N=50):
M=M+N
N=M-N
print(M,"@",N)
return(M)
A=200
B=100
A=Alter(A,B)
print(A,"#",B)
B=Alter(B)
print(A,"@",B)
Ans :
300 @ 200
300 # 100
150 @ 100
300 @ 150
25. Differentiate between pickling and unpickling.
26. What is the output of the below program?
x = 50
def func(x):
print('x is', x)
x=2
print('Changed local x to', x)
func(x)
print('x is now', x)

27. Complete the following snippet to open the file and create a writer object for a csv file “emp.csv” with
delimiter as pipe symbol „|‟ to add 5 more records into the file using the list named “e_rec”.
emp_file=___________
csv_writer=csv.writer( ____________ )
Ans:
emp_file=open(“emp.csv”,”ab”)
csv_writer=csv.writer( e_rec,emp_file )
28. Consider the given string and write the output for the following:
Str1=”Augmented reality”
a) Str1[0:3] b) Str1[::3]
Ans: a) Aug b) “Amt at”

SECTION-C (30 MINS)(3*3 = 9MARKS)


29. What will be the output of the following code:
sub = “083 Comp. Sc. & 065 Info. Prac.”
n = len(sub)
s=’’
for i in range(n):
if sub[i].isupper():
s = s + sub[i].lower()
elif sub[i].islower():
s = s + sub[i]
elif sub[i].isdigit():
s = s + ‘x’
elif sub[i].isspace():
pass
else:
s = s + ‘!’
print(s)
Answer:
xxxcomp!sc!!xxxinfo!prac!
30. (a) Given is a Python string declaration:
title="## T20 W’Cup 2022@@"
Write the output of: print(title[::-1])
(b) Write the output of the code given below:
my_dict = {"name": "Aman", "age": 26}
my_dict['age'] = 27
my_dict['address'] = "Delhi"
print(my_dict.items())
Ans: (a) @@2202 puC’W 02T ## 1 marks for each correct row
(b) Ans: dict_items([('name', 'Aman'), ('age', 27), ('address', 'Delhi')])
31. a) Differentiate between mutable and immutable objects in python language with example.
b) Evaluate the expression: 5= =3 or 9<2 and 2 = = 2 or not 4>1 Ans: False

SECTION- D (40 MINS)(4*4 =16MARKS)


32. Write a function countbb() in Python, which reads the contents from a text file ‘article.txt’ and displays
number of occurrences of words ‘bat’ and ‘ball’ (in all possible cases) to the screen.
Example:
If the content of file article.txt is as follows:
Bat and ball games are field games played by two opposing teams. Action starts when the defending team throws
a ball at a dedicated player of the attacking team, who tries to hit it with a bat and run between various safe areas
in the field to score runs (points). The defending team can use the ball in various ways against the attacking team's
players to force them off the field when they are not in safe zones, and thus prevent them from further scoring.
The best known modern bat and ball games are cricket and baseball, with common roots in the 18th-century
games played in England.
The countbb() function should display as:
Number of times bat occurs is 3
Number of times ball occurs is 5
Answer:
def countbb():
fin = open('article.txt', 'r')
data = fin.read()
fin.close()
L = data.split()
bat=ball=0
for i in L:
i = i.rstrip(".,;-'")
if i.upper() == 'BAT':
bat += 1
elif i.upper() == 'BALL':
ball += 1
print("Number of times bat occurs",bat)
print("Number of times ball occurs",ball)
33. What is the difference between CSV file and Text File? Write a program in Python that defines and calls the
following functions:
Insert() – To accept details of clock from the user and stores it in a csv file ‘watch.csv’. Each record of clock
contains following fields – ClockID, ClockName, YearofManf, Price. Function takes details of all clocks and
stores them in file in one go.
Delete() – To accept a ClockID and removes the record with given ClockID from the file ‘watch.csv’. If ClockID
not found then it should show a relevant message. Before removing the record it should print the record getting
removed.

Answer:
Text files are plain text files which are used to store any kind of text which has no fixed
format. whereas, CSV files are also text files but they can store information in a specific
format only.
def Insert():
L=[]
while True:
ClockID = input("Enter Clock ID = ")
ClockName = input("Enter Clock Name = ")
YearofManf = int(input("Enter Year of Manufacture = "))
price = float(input("Enter Price = "))
R = [ClockID, ClockName, YearofManf, price]
L.append(R)
ans = input("Do you want to enter more records (Y/N)=")
if ans.upper()=='N':
break
import csv
fout = open('watch.csv','a',newline='')
W = csv.writer(fout)
W.writerows(L)
fout.close()
print("Records successfully saved")
def Delete():
ClockID = input("Enter Clock ID to be removed = ")
found = False
import csv
fin = open('watch.csv','r')
R = csv.reader(fin)

34. Write a function V_COUNT() to read each line from the text file and count number of lines begins and ends with
any vowel.
Example:
Eshwar returned from office and had a cup of tea.
Veena and Vinu were good friends.
Anusha lost her cycle.
Arise! Awake! Shine.
The function must give the output as:
Number of Lines begins and ends with a vowel is 3
Ans:
def V_COUNT():
f=open("string_begin.txt","r")
L=" "
c=0
for i in f:
print(len(i))
if i[0] in"aeiouAEIOU" and i[-2] in "aeiouAEIOU":
c=c+1
print("Number of Lines begins and ends with a vowel is",c)
V_COUNT()

35. a) What is the difference between readline() and readlines()?


b) How to catch zero division error in python? Explain with example.

SECTION-E (40 MINS) (2*5 =10MARKS)


36. What is the use of CSV file in Python Programming? how its helps to store data in it.? Write a program in
Python that defines and call the following user define functions:-
add() – To accept and add data of an student in to a CSV file “school.csv”. Each record consists of a list with field
elements as sid, sname and class to add student id, student name and class respectively.
Count() – To count the number of records present in the CSV file named ‘school.csv’ .
Ans:
CSV file in python programming helps to store data like a text file in a format COMMA SEPERATED VALUE.
The extension of CSV file is .csv , it’s a Human Redable format. This file can be open in Excel and Notepad also
import csv
def add():
fout=open(“school.csv”,’a’, “newline=’\n’)
wrow=csv.writer(fout)
sid=int(input( “enter the student id”))
sname=input(“enter the student name”)
class=int(input(“enter class in number in which student studying”))
row=[sid,sname,class]
wrow.writerow(row)
fout.close()
def Count():
fin=open((“school.csv”,’a’, “newline=’\n’)
data=csv.reader(fin)
record=list(data)
print(len(record))

37. Explain handling exceptions in python with syntax and examples.

(LAST 10 Mins for Checking)

You might also like