XII CS PT1 Practice Paper

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

THE SCINDIA SCHOOL, FORT, GWALIOR

PERIODIC TEST I PRACTICE PAPER 2023-24


CLASS: XII SUBJECT: COMPUTER SCIENCE
TIME: 2 Hrs M.M.: 40
_________________________________________________________________________________
General Instructions:
 The question paper is divided into 3 sections – A, B, C, D and E.
 Section A consists of 8 questions (1-8). Each question carries 1 mark.
 Section B consists of 5 questions (9-13). Each question carries 2 marks.
 Section C consists of 3 questions (14-16). Each question carries 3 marks.
 Section D consists of 2 questions (17-18). Each question carries 4 marks.
 Section E consists of 1 question (19) and it carries 5 marks.

Section -A
Each question carries 1 mark
1 True or False: 1
“The 'not' operator in Python is used to perform logical negation, i.e., it reverses the truth
value of a condition.”True
2 Which of the following will result in an error? 1
str1=” python”
a) print(str1[2]) b) str1[1]="x"
c) print(str1[0:9]) d) Both (b) and (c)
3 What will be the output of the following Python code? 1
>>>t = (1, 2, 4, 3, 8, 9)
>>>[t[i] for i in range(0, len(t), 2)]
a) [2, 3, 9] b) [1, 2, 4, 3, 8, 9]
c) [1, 4, 8] d) (1, 4, 8)
4 Select the correct method to write a list of lines to a file 1
a) write(list)
b) writelines(list)
c) writelist(list)
d) None of these
5 Assertion and Reason-based questions. Mark the correct choice: 1
(i) Both A and R are true and R is the correct explanation for A
(ii) (ii) Both A and R are true and R is not the correct explanation for A
(iii) A is True but R is False
(iv) A is False but R is True
Assertion (A): - The number of actual parameters in a function call may not be equal to
the number of formal parameters of the function.
Reasoning (R): - During a function call, it is optional to pass the values to default
parameters.
6 1

AKL Page 1 of 4
7 Predict the output: 1

67
145
234
313
Sum of All 313
8 Write the output of the code given below: 1

400 420
Section -B
9 What is a token? Give two examples. 2
A token is the smallest individual unit in a python program. Keyword and
Identifiers
10 What is the need of a file? What are the different types of files? 2
A file is a sequence of bytes on the disk/permanent storage where a group of related
data is stored. File is created for permanent storage of data. Text file and Binary
file
11 What will be the output for the following code? Also, write the reason. 2
def string_both_ends(str):
if len(str) < 2:
return ‘ ‘
return str[0:2] + str[-2:]
print(string_both_ends('Term1 Exam'))
Team
12 What would be the data type of variable data in the following statements? 2
(a) data = f.read()
(b) data = f.read(10)
(c) data = f.readline()
(d) data = f.readlines()
(a)Stringtype.
(b)Stringtype.
(c)Stringtype.
(d) List type.
13 Write the corresponding Python assignment statements: 2
i)Assign 10 to variable length and 20 to variable breadth.
ii)Assign the average of values of variables length and breadth to a variable sum.
length = 10
breadth = 20

AKL Page 2 of 4
sum = (length + breadth) / 2
Section -C
14 Which data type will be used to represent the following data values and why? 3
(a) Number of months in a year Integer
(b) Resident of Delhi or not Boolean
(c) Mobile number String
(d) Pocket money Float
(e) Volume of a sphere Float
(f) Perimeter of a square Float
15 Give step by step execution of the following expressions? 3
(10*1*2**4-4//4)

Let's break down the expression step by step:


1. 2**4: This is the exponentiation operation, which means 2 raised to the power of
4. It results in 16.
2. 4//4: This is the floor division operation, which means dividing 4 by 4 and
rounding down to the nearest integer. It results in 1.
3. 10*1*16: Multiplication operation is executed first. The multiplication of 10, 1,
and 16 results in 160.
4. 160-1: Subtraction operation is executed next. The result of 160 minus 1 is 159.
So, the final output of the expression is 159.

16 Rewrite the following code in Python after removing all syntax error(s). Underline each 3
correction done in the code.
DEF execmain():
x = input("Enter a number:")
if (abs(x)=x):
print ("You entered a positive number")
else:
x=*-1
print("Number made positive:",x)
call_execmain()
def execmain():
x = int(input("Enter a number:"))
if abs(x) == x:
print("You entered a positive number")
else:
x = -x
print("Number made positive:", x)

In the corrected code:


1. The function definition is written as def execmain():.
2. The int() function is used to convert the input to an integer, allowing us to use
mathematical operations on it.
3. The comparison in the if statement is fixed using == instead of =.
4. The abs() function is used to check if the number is positive by comparing its
absolute value with the original value.
5. The unwanted * character is removed from the line x=*-1 to make the number
positive, and -x is used instead.
6. The call_execmain() function call is changed to execmain() to call the correct
function.

Section -D
17 i)Explain the concept of flow control in Python. 2
ii)Give the syntax for if else and if elif else. 2

AKL Page 3 of 4
Python control flow. Control flow is the order in which individual statements,
instructions, or function calls are executed or evaluated. The control flow of a Python
program is regulated by conditional statements, loops, and function calls.

18 i)Differentiate between relative and absolute paths. 2


ii) Give examples for both . 2
Section -E
19 Write a program that reads characters from the keyboard one by one. All lower case 5
characters get stored inside the file LOWER.txt, all upper case characters get stored
inside the file UPPER.txt and all other characters get stored inside file OTHERS.txt.

OR

Write a function count_vowel() to count the total number of vowels in a text file
“Vowelcheck.txt”.
If the text file contains:
PT-1 Examination 2023 begins on 24 July 2023

The output should be: 10


***

AKL Page 4 of 4

You might also like