0% found this document useful (0 votes)
37 views

Delhi Public School, Gandhinagar Half Yearly Examination (2023-24) Computer Science (Set-1)

Uploaded by

duh.compwork
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)
37 views

Delhi Public School, Gandhinagar Half Yearly Examination (2023-24) Computer Science (Set-1)

Uploaded by

duh.compwork
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
You are on page 1/ 8

Delhi Public School, Gandhinagar

Half Yearly Examination (2023-24)


Class: XI Computer Science Date: 20.09.2023
Time: 3 Hours (Set-1) M. Marks: 70

Name: _______________________________ Sec: _________ Roll No.: ________

General Instructions:
1. This question paper contains 35 questions.
2. The paper is divided into 5 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. What would the following code fragment do? 1
import random
import math
fnum=random.random()*(100-60)+60
inum=math.ceil(fnum)
print(inum)
a) Generates a random floating number in b) Generates a random floating number in
the range 60 to 100 and displays its the range 60 to 100 and displays its
nearest higher integer nearest lower integer
c) Generates a random floating number in d) Generates a random integer in the range
the range 40 to 60 and displays its nearest 40 to 100 and displays an integer higher
higher integer than it.
2. What would be displayed on the execution of the following code? 1
X="hello123"
Y="123"
print(type(X))
print(type(int(Y)))
print(type(X==Y))

Page 1 of 8
a) b)
<class 'str'> string
<class 'int'> int
<class 'bool'> boolean
c) d)
<class 'str'> int
<class 'str'> int
<class 'bool'> boolean
3. Which type of error occurs when an operation or function receives an inappropriate type 1
value?
a) ValueError b) TypeError
c) NameError d) IndexError
4. Which of the following is the correct way to declare a string variable named fruit in 1
Python?
a) fruit = 'banana" b) fruit = banana
c) fruit = 'banana' d) "banana" = fruit
5. The ______________mode of Python gives instant results of typed statements. 1
a) Interactive mode b) Script mode
c) Command mode d) Combination of interactive and script
modes
6. Which one is a valid relational operator in Python? 1
a) / b) =
c) == d) and
7. Which of the following is not a function of the statistics module in Python? 1
a) mean() b) median()
d) mode() d) average()
8. Identify the valid declaration of L: 1
L = [1, "23", "Hi", 6]
a) list b) dictionary
c) array d) tuple
9 What is the default value for the end argument of print()? 1
a) '\n' (newline) b) ' ' (space)
c) '\t' (tab) d) ',' (comma)
10. Which of the following statement(s) would give an error after executing the following 1
code?
S="Welcome to class XI" # Statement 1
print(S) # Statement 2

Page 2 of 8
S="Thank you" # Statement 3
S[0]= '@' # Statement 4
S=S+"Thank you" # Statement 5
a) Statement 3 b) Statement 4
c) Statement 5 d) Statements 4 and 5
11. Given the following code, choose the correct output. 1
a=3
b=2
for i in range(1,a):
for j in range (1,b):
print ("hello"*i+"oswal"*j)
a) b)
hello hello
hellohello oswaloswal
c) d)
hello hellooswal
hellooswal hellohellooswal
12. What shall be produced on the execution of the following code? 1
a = True
b = False
c = False
if not a or b:
print(1)
elif not a or not b and c:
print(2)
elif not a or b or not b and a:
print(3)
else:
print(4)
a) 1 b) 2
c) 3 d) 4
13. Which of the following is not a legal string operation? 1
a) "KV"+"KDML" % 2 b) 'Kendriya'+'Vidyalaya'
c) "K"+"V"+"KDML" d) 'KV' * 5
14. Function range(3) is equivalent to: 1

a) range(1,3) b) range(0,3)
c) range(3,0,-1) d) range(1,3,1)

Page 3 of 8
15. Choose the correct output for the following code. 1
A=[2,4,6,8,10]
L=len(A)
S=0
for I in range(1, L, 2):
S+=A[I]
print("Sum=", S )
a) Sum= 18 b) Sum= 30
c) Sum= 12 d) Sum= 16
16. What would be the output of the following code fragment? 1
L=['we',['are','going'],'to',['have','fun'],'with','lists']
print("fun" in L[3])
print("fun" in L[3:4])
print(L[1:2]+L[2:3])
a) b)
True True
False True
[['are', 'going'], 'to'] [['are', 'going'], 'to']
c) d) Error
True
False
['are', 'going', 'to']
Q17 and 18 are ASSERTION AND REASONING based questions. Mark the correct
choice as
a) Both A and R are True and R is the correct explanation for A
b) Both A and R are True and R is not the correct explanation for A
c) A is True but R is False
d) A is False but R is True
17. Assertion (A): In an if else statement, the if block is executed when the condition 1
evaluates to true, and the else block is executed when the condition evaluates to false.
Reason (R): if else is a conditional construct where else block is mandatory.
18. Assertion (A): In Python, strings, lists, and tuples are called sequences. 1
Reason (R): Sequence is referred to as an ordered collection of values having similar or
different data types.

SECTION - B
19. i) What is a block or suite in Python? 2
ii) Explain the usage of capitalize() method.

Page 4 of 8
20. Rewrite the following after removing all syntax errors. Underline each correction. 2
for name range[amar,shveta,parag]:
IF name[0] ="S":
print(name)
21. Write a Python program that inputs a string, and displays the count of words starting with 2
the letter 'H' (not case-sensitive).
OR
Write a program to generate random values for hours (0-23), minutes (0-59), and seconds
(0-59). The program should then join hours, minutes, and seconds with a colon (:)
separator and display the generated time.
22. Write the output of the following code fragment: 2
L=[10,20,30,40]
L1=[500,600]
L2=[35,45]
L1.extend(L2)
L.insert(2,25)
print (L1+L2)
print (L1)
print (L.index(30))
print (L2*2)
23. Find the output for the following code fragments. 2
i) str="Educating the world in different spheres"
print("The position of 'in' at:", str.find('in'))
ii) str='board exam'
print(str.split('a'))
24. Write an algorithm to find out whether the given number is divisible by 3 or not. 2
25. Find the output of the following code fragment: 2

Page 5 of 8
SECTION – C
26. i) Write the output of the following: 3
L=['a','z','p','c','m']
L.remove('c')
print (L)
print (L.pop())
ii) Find the output of the following Python code:
for Subject in ['Physics', 'Chemistry', 'Mathematics', 'English']:
print(Subject)
if Subject[0]=='M':
break
else:
print('Compulsory')
print('Optional')
iii) According to the precedence of operators solve the following and write the final answer.
(Show steps according to the precedence of operators)
19%4 -17 / 2 * 3 + 2**3 +5//2
27. Write the function/method to do the following: 3
i) To remove the trailing spaces from the string.
ii) To check for an alphabet or a digit.
iii) To trim the spaces both from the left and right side.
iv) To split the string at the first occurrence of a separator.
v) To sort a list in the reverse order.
vi) To remove an item from the list at the end.
28. Write a program to input two numbers and display their HCF (Highest Common Factor). 3
OR
Write a program to input the number of lines and display the following pattern as per the
number of lines input.
1
13
135
1357
29. i) What is the difference between == and = operator? 3
ii) What is an infinite loop?
iii) What is the role of an identifier in a program?
30. Write a program to calculate how many days a work will be completed by three persons 3
A, B, and C together (rounded up to 1 decimal place). A, B, and C take x days, y days, and
z days respectively to do the job alone. The formula to calculate the number of days if the

Page 6 of 8
work is done together is xyz/(xy+yz+zx) days where x, y, and z are given as input to the
program.

SECTION – D
31. i) What would Python produce for the following code, if the input given for variable x is 4
a) Just return key pressed, no input given
b) 0
#code
x=bool(input('Enter Data:'))
print(x and 10<13-2)
print((10 and 5) or x)
ii) What will be displayed on the screen for the following code fragment?
value = [5,4,3,2,1,0]
print(value[0])
print (value[value[0]])
print(value[value[-2]])
print(value[value[value[value[2]+1]]])
32. Write a program to input three sides of a triangle and display if a triangle is possible or 4
not. If the triangle is possible, evaluate if it's equilateral, isosceles, or scalene and calculate
its area using Heron's formula.
If a, b, and c are the three sides of a triangle:
𝑎+𝑏+𝑐
𝑠= , 𝑎𝑟𝑒𝑎 = √𝑠(𝑠 − 𝑎)(𝑠 − 𝑏)(𝑠 − 𝑐)
2
Where s is semi-perimeter

SECTION – E
33. Krishna of class 11 is writing a program to check whether the square root of a given 5
number is prime or not. Some of the code segment is written below. Help him to complete
the program.
import ______________ #Line 1
n = int(______________("Enter a number:")) #Line 2
m = int(__________(n)) #Line 3
k=0
for i in _________(2, m//2+1): #Line 4
if (m%i==0):
k=k+1
if (k == 0):
print(m,"Which is a square root of ", n, "is Prime number.")
else:
print(m, "Which is a square root of ", n, "is not Prime number.")

Page 7 of 8
i) Name the module he should import in Line 1.
ii) Name the function he should use in Line 2 for input.
iii) Write the missing code to find the square root in Line 3.
iv) Complete the missing statement in Line 4 with an appropriate function.
v) What will be the output if the value of n is given by the user is 64?
34. i) Differentiate between Keywords and Literals in Python with suitable examples. 5
ii) Write a program to input a list Lst and two numbers M and N. Then create a new list from
those list elements which are divisible by both M and N.
OR
Write a program to compare two equal-sized lists and print the first index where they
differ.
35. Do as directed 5
i) When does syntax error occur in Python?
ii) Given two lists
L1=["this", "is", "a", "List"]
L2=["this", ["is", "another"], "List"]
Which of the following will cause an error and why?
a) L1.upper()
b) L1[3].upper()
c) L2[1][1].upper()
d) L2[1:2][0].lower()
iii) Predict the output of the following:
a,b,c=10,20,10
print(a==b)
print(a is c)
iv) Find the output of the following code fragment:
n=[1,4,2,6,9,5]
print(n[:4])
print(n[-1:-4:-2])
v) What will be the output of the code fragment given below?
x=20
x=x+5
x=x-10
print (x)
x,y=x-1,50
print (x,y)

Page 8 of 8

You might also like