0% found this document useful (0 votes)
17 views7 pages

Half Yearly 12 CS Set A

The document is a question paper for the Half Yearly Examination 2024 for XII Science Computer Science (083) at St. Stephen’s Senior Secondary School, Ajmer. It contains 35 questions divided into 5 sections, covering various topics in Python programming, with a total of 70 marks. Each section has a different marking scheme, and all programming questions must be answered using Python.

Uploaded by

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

Half Yearly 12 CS Set A

The document is a question paper for the Half Yearly Examination 2024 for XII Science Computer Science (083) at St. Stephen’s Senior Secondary School, Ajmer. It contains 35 questions divided into 5 sections, covering various topics in Python programming, with a total of 70 marks. Each section has a different marking scheme, and all programming questions must be answered using Python.

Uploaded by

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

St.

Stephen’s Senior Secondary School, Ajmer


Half Yearly Examination 2024
XII Science
Computer Science (083)
Maximum Marks: 70 Time Allowed: 3 hours

General Instructions:
1. Please check this question paper contains 35 questions.
2. The paper is divided into 4 Sections- A, B, C, D and E.
3. Section A, consists of 18 questions (1 to 18). Each question carries 1 Mark.
4. Section B, consists of 7 questions (19 to 25). Each question carries 2 Marks.
5. Section C, consists of 5 questions (26 to 30). Each question carries 3 Marks.
6. Section D, consists of 2 questions (31 to 32). Each question carries 4 Marks.
7. Section E, consists of 3 questions (33 to 35). Each question carries 5 Marks.
8. All programming questions are to be answered using Python Language only.

Section - A
1 State True or False : 1
"In Python, tuple is a mutable data type".

2 Identify the valid Python identifier from the following: 1


a) @count b) None
c) count_ d) 123count

3 Select the correct output of the code : 1


S = "text#next"
print(S.strip("t"))

a) ext#nex b) ex#nex
c) text#nex d) ext#next

4 Which of the following is/are valid assignment operator in Python: 1


a) //= b) ? c) <= d) and
e) ++ f) *= g) in h) >=

5 For the following Python statement: 1


N = (25)
What shall be the type of N?
a) Integer b) String
c) Tuple d) List

6 Consider the statements given below and then choose the correct output from the given 1
options:
S="DIGITAL#INDIA"
print(S[-4: 1 :-2])
a) N#AI b) TG
c) N#AII d) No Output

1
7 When is the ‘finally’ block executed? 1
a) When there is no exception
b) When there is an exception
c) Only if some condition that has been specified is satisfied
d) Always

8 State whether the following statement is True or False: 1


A try block in Python must always be followed by an except block.

9 Manasvi, a student wants to write code to check whether the given no. is even or odd. But she 1
stuck with code. Help her to fill the gaps with correct statement.
num=int(input('Enter a number '))
if __________ :
print(num, 'is Even')
else:
print(num, 'is Odd')

10 What will the following expression be evaluated to in Python? 1


print(6*3 / 4**2//5-8)
a) -10 b) 8.0
c) 10.0 d) -8.0

11 What will be the output of the given code? 1


a=10
def convert(b=20):
a=30
c=a+b
print(a,c)
convert(30)
print(a)

12 Which of the following are not true about Python strings? 1


i) Strings are immutable.
ii) Strings can be concatenated using the + operator.
iii) Strings can be sliced, but the original string is modified.
iv) String elements are accessed using square brackets.
a) i, ii b) iii only
c) i, iii, iv d) ii, iii

13 Suppose content of 'Myfile.txt' is 1


Honesty is the best policy.

What will be the output of the following code?


myfile = open("Myfile.txt")
x = myfile.read()
print(len(x))
myfile.close()
a) 5 b) 25
c) 26 d) 27

2
14 Assume that the position of the file pointer is at the beginning of 3rd line in a text file. Which 1
of the following option can be used to read the next single line from the file?
a) myfile.read( ) b) myfile.read(n)
c) myfile.readline( ) d) myfile.readlines( )

15 Name the built-in mathematical function / method that is used to return the smallest integer 1
less than or equal to N.

16 Which of the following statements about the tell( ) method is true? 1


a) It changes the current file position to the end of the file.
b) It returns the current file position as an integer.
c) It deletes the file pointer.
d) It reads the current file pointer as a string.

17 Assertion (A): Global variables are accessible in the whole program. 1


Reason (R): Local variables are accessible only within a function or block in which it is
declared.

a) Both Assertion (A) and Reason (R) are true and Reason (R) is the correct explanation of
Assertion (A).
b) Both Assertion (A) and Reason (R) are true, but Reason (R) is not the correct explanation of
Assertion (A).
c) Assertion (A) is true, but Reason (R) is false.
d) Assertion (A) is false, but Reason (R) is true.

18 Assertion (A): If numeric data are to be written to a text file, the data needs to be converted 1
into a string before writing to the file.
Reason (R): write() method takes a string as an argument and writes it to the text file.

a) Both Assertion (A) and Reason (R) are true and Reason (R) is the correct explanation of
Assertion (A).
b) Both Assertion (A) and Reason (R) are true, but Reason (R) is not the correct explanation of
Assertion (A).
c) Assertion (A) is true, but Reason (R) is false.
d) Assertion (A) is false, but Reason (R) is true.

Section - B
19 Raman has written a code to find its sum of digits of a given number passed as parameter to 2
function sumdigits(n). His code has errors. Rewrite the correct code and underline the
corrections made.
def sumdigits(n)
d=0
for x in str(n):
d=d+x
return d
n=int(input('Enter any number"))
s=sumdigits(n)
print("Sum of digits", s)

3
20 Write the Python statement for the following tasks using BUILT-IN functions/methods only: 2
i) To delete an element 10 from the list lst.
ii) To replace the string "This" with "That" in the string str1.

21 Predict the output of the following code: 2

def Total (Num=10):


Sum=0
for C in range(1,Num+1):
if C%2!=0:
continue
Sum+=C
return Sum
print(Total(4),end="$")
print(Total(),sep="@")

22 What is the purpose of the return statement in a function? Illustrate with an example. 2

23 Predict the output of the Python code given below: 2

data=["L",20,"M",40,"N",60]
times=0
alpha=""
add=0
for c in range(1,6,2):
times = times + c
alpha = alpha + data [c-1] + "@"
add = add + data[c]
print (times, add, alpha)

24 Predict the output of the following code: 2

d = {"apple": "fruit", "carrot": "vegetable", "banana": "fruit"}


str_result = ""
for item in d:
str_result += d[item] + "|"
final_str = str_result[:-1]
print(final_str)

25 Which of the following output will never be obtained when the given code is executed? 2

import random
Shuffle = random.randrange(10)+1
Draw = 10*random.randrange(5)
print ("Shuffle", Shuffle, end="#")
print ("Draw", Draw)

a) Shuffle 1 # Draw 0 b) Shuffle 10 # Draw 10


c) Shuffle 10 # Draw 0 d) Shuffle 11 # Draw 50

4
Section – C
26 Write the definition of a method/function SearchOut(Teachers, TName) to search for 3
TName from a list Teachers, and display the position of its presence.
For example :
If the Teachers contain ["Ankit", "Siddharth", "Rahul", "Sangeeta", "rahul"]
and TName contains "Rahul"
The function should display
Rahul at 2
rahul at 4

27 Find and write the output of the following Python code: 3

def Calculate(X=30, Y=20):


X=X/Y
Y=X+Y
print(X, '!', Y)
return X

P = 80
Q = 40
P = Calculate(P, Q)
print(P, '!', Q)
Q = Calculate(Q)
print(P, '!', Q)

28 Predict the output of the Python code given below: 3


s="India Growing"
n = len(s)
m=""
for i in range (0, n) :
if (s[i] >= 'a' and s[i] <= 'm') :
m = m + s [i].upper()
elif (s[i] >= 'O' and s[i] <= 'z') :
m = m +s [i-1]
elif (s[i].isupper()):
m = m + s[i].lower()
else:
m = m + '@'
print (m)

29 Write a method/function COUNTWORDS( ) in Python to read contents from a text file 3


DECODE.TXT, to count and return the occurrence of those words, which are having 6 or
more characters.
Example:
If the file content is as follows:
An apple a day keeps the doctor away. We all pray for everyone’s safety.
A marked difference will come in our country.
The COUNTWORDS( ) function should display the output as:
6

5
30 What possible outcome will be produced when the following code is executed? Also mention 3
the maximum and minimum value that can be assigned to the variable value.

import random
value=random.randint(0,3)
fruit=["APPLE","ORANGE","MANGO","GRAPE"]
for i in range(value):
print(fruit[i],end='##')
print()

a) APPLE## b) APPLE#
ORANGE##

c) APPLE## ORANGE## d) ORANGE##


MANGO##
APPLE##

Section - D
31 Write a function in Python that displays the book names having 'Y' or 'y' in their name from a 4
text file "Bookname.txt".

Example :
If the file Bookname,txt contains the names of following books :
One Hundred Years of Solitude
The Diary of a Young Girl
On the Road

After execution, the output will be :


One Hundred Years of Solitude
The Diary of a Young Girl

32 Sangeeta is a Python programmer working in a computer hardware company. She has to 4


maintain the records of the peripheral devices. She created a csv file named Peripheral.csv, to
store the details.

The structure of Peripheral.csv is:


[P_id,P_name,Price]

where
P_id is Peripheral device ID (integer)
P_name is Peripheral device name (String)
Price is Peripheral device price (integer)

Sangeeta wants to write the following user defined functions:


 Add_Device( ): to accept a record from the user and add it to a csv file, Peripheral.csv
 Count_Device( ): To count and display number of peripheral devices whose price is
less than 1000.

6
Section - E
33 A binary file “salary.dat” has structure [employee id, employee name, salary]. What the 5
following code will display:

def records( ):
num=0
fobj=open("data.dat"," ____ ") # Line 1
try:
print("Emp id\tEmp Name\tEmp Sal")
while True:
rec=pickle._________(fobj) # Line 2
if rec[2]< 20000:
print(rec[0],"\t\t",rec[1],"\t\t",rec[2])
except:
________________ # Line 3
_________________ # Line 4

a) Mention the mode in which the file should be opened in Line 1

b) Write the name of the function used in Line2, for reading data from the file.

c) Write the statement to close the file marked as Line 3

d) Fill in the blank in Line 4 to call the function records( )

e) What is the import statement that should be given to execute the program?

34 A list contains the following record of students ([studname , mark]). Write the following user 5
defined functions to perform given operations on stack named ‘stud’.
i) push_stud() - To push students names to stack whose mark is more than 250
ii) pop_stud() - To pop the names of students from stack and display them.
Also display “Underflow” when there are no students in the stack.
Example:
If the list contains:
[['Rahul',450],['Deepa',200],['Uma',400],['Sidharth',230]]
The stack should contain
Rahul
Uma
The output should be:
Uma
Rahul
Underflow

35 i) What is the main purpose of seek() and tell() method ? 5


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.

You might also like