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

Set-B

Class XI Computer Science Second Term Exam 2022-23 Answer Key


SECTION A
1. Identify the option that contains only Python's keyword. [1]
a) pass, eval, else, elif
b) break, elif, else, from
c) from, else, eval, import
d) from, round, pass, else

2. Identify the option which contains only functions from math module. [1]
a) log(), log10(), round(), sin()
b) floor(), ciel(), max(), abs()
c) sin(), count(), log10(), pow()
d) sin(), cos(), log(), sqrt()

3. Identify the option which contains only literals. [1]


a) not, None, 'True', 7.2
b) 100, True, 'False', None
c) None, False, True, and
d) 100, 'None', 6.2, fail

4. Which string method would convert a string 'AHMADI, kuwait' to 'ahmadi, KUWAIT'? [1]
a) title()
b) capitalize()
c) swapcase()
d) lower()

5. What will be the output of the code given below? [1]


astr="SHOWCASE"
print(astr[4:]+astr[:4]*2)
a) SHOWCASESHOWCASE
b) SHOWCASECASE
c) CASESHOWCASESHOW
d) CASESHOWSHOW

6. Identify the statement that will trigger an error. [1]


data=[10,20]
a) data+=range(30,51,10)
b) data+='MANGO'
c) print(data+'GRAPE')
d) data*=-5

7. Evaluate the expression: 'WORLD' or 56321 and 671.5 [1]


a) 671.5 b) 56321 c) 'WORLD' d) WORLD

8. Evaluate the expression: 9+3**2%3**5//2-5 [1]


a) 12 b) 13 c) 8 d) 9

9. Select the correct output. [1]


word="GOODBADUGLY"
word=word.partition('BAD')
print(word[1], word[2], word[0], sep='<-')
a) GOOD<-UGLY<-BAD
b) GOOD<-BAD<-UGLY
c) BAD<-UGLY<-GOOD
d) UGLY<-GOOD<-BAD
Page 1/7
Set-B
Class XI Computer Science Second Term Exam 2022-23 Answer Key
10. Select the correct output: [1]
alist=[22,44,66,55,33,11]
del alist[3], alist[3]
print(sum(alist))
a) 198 b) 165 c) 121 d) 143

11. Identify the statement that will delete the last element from the list. [1]
alist=[25, 'SMARTH', 65.0, 30.0, 'A1']
a) alist.pop('A1')
b) alist.remove(-1)
c) alist.pop(4)
d) alist.remove()

12. print(round(82347.75, -2)) will display [1]


a) 82347.0 b) 82340.0 c) 82300.0 d) 82000.0

13. Identify the correct output. [1]

metal={"gold":"au", "silver":"ag", "iron":"fe"}


check="silver" in metal
print(check)
a) True b) Error c) None d) False

14. Identify the correct output. [1]


astr='CORROSION'
alist=astr.split('O')
print(max(alist)+min(alist))
a) SIC b) CIS c) ISC d) SCI

15. Identify the correct output. [1]


astr='\n\t\n\tINDIA\t\tNEW\t\tDELHI\n\t'
bstr=astr.lstrip()
print(len(bstr))
a) 17 b) 19 c) 21 d) 23

16. Identify the correct output. [1]


x=['CHROME', 'SAFARI', 'EDGE']
y='::'.join(x)
print(y)
a) CHROME::SAFARI::EDGE::
b) CHROME::SAFARI::EDGE
c) ::CHROME::SAFARI::EDGE
d) CHROME:SAFARI:EDGE:

Question Numbers 17 and 18 are Assertion and Reason based questions. Mark the correct choice:
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): z=25.7, assigning new value to variable z will generate new ID.
Reasoning(R): Variable z is immutable type. Ans: 17. b) [1]

18. Assertion (A): Python dictionary key is immutable type.


Reasoning (R): Python dictionary value can be any type. Ans: 18. b) [1]

Page 2/7
Set-B
Class XI Computer Science Second Term Exam 2022-23 Answer Key

SECTION B
19. Give the output of Python code given below: [2]
python='PYTHON$SUPPORTS#OOP' HNSPOT
print(python[3:-5:2]) SRPU$O
print(python[-5:3:-2])

20. After the execution of Python program given below, what will be the possible correct output(s)? What will
be the maximum value and minimum value stored in the variable start?
[2]
from random import randint
alist=[25,45,65,85,75,55,35,15] Possible correct outputs:
start=randint(2,5) a) 35#55#75#85# b) 55#75#85#65#
for k in range(start, start+4):
Max: 5 Min: 2
print(alist[-k], end='#')
a) 35#55#75#85# b) 55#75#85#65# c) 65#85#75#55# d) 85#75#55#35#

21. Rewrite the Python program given below by replacing the while loop with a for loop: [2]
n=int(input('Input n? ')) n=int(input('Input n? '))
s, k=0, n s=0
while True: for k in range(n, 0, -1):
s+=2*k s+=2*k
if k==1: break print(s)
k-=1
print(s)
What will be the output of the Python program, when the inputted value of n is 10? Ans: 110

22. Identify the type of token form the list given below: [2]
a) break b) len() c) == d) {}
Keyword Identifier Operator Delimiter

23. Write two differences between mutable type and immutable type. [2]
Mutable Immutable
 Can be updated  Cannot be updated
 

24. What are two differences between built-in function sorted() and list method sort()? [2]
sorted() sort()
 Independent built-in function  List method
 Accepts list / tuple / str / dictionary as parameter  Only sorts a list, cannot sort tuple / str / dictionary
 Returns a sorted list  Returns None
 Does not sort list / tuple / str / dictionary  Physically sorts a list
physically

25. With suitable example explain the concept of logical error. [2]
Logical error: Syntactically correct Python statement gives unexpected result or output due to flaw or error
in the logic or in the design of the code. Program execution never stops (does not crash). Examples: using
wrong type of variable, initializing accumulator or counter incorrectly, using floor division instead of real
division or vice-versa.

26. With examples explain the use of else with either for-loop or while loop. [2]
A while loop / for loop with else part is executed A while loop / for loop with else part does not
when the loop is terminated normally. executed when the loop is terminated abnormally
for x in range(1,6): using break.
print(x, end=' ') for x in range(1,11):
Page 3/7
Set-B
Class XI Computer Science Second Term Exam 2022-23 Answer Key
else: print(x, end=' ')
print('End of Loop') if x==5: break
Execution of the code produces following output: else: print('End of Loop')
1 2 3 4 5 End of Loop Execution of the code produces following output:
else part gets executed because for loop terminates 1 2 3 4 5
normally when x is 5. else part does not get executed because for loop is
terminated abnormally using break.

SECTION C
27. Rewrite the complete Python program after removing all the errors. Underline the corrections. [3]
import random.randint from random import randint
alist==() alist=()
FOR x in range(10): for x in range(10):
num=randint(100) num=randint(10,99)
alist+=(num) alist+=(num,)
print(alist) print(alist)
print(sum[alist]) print(sum(alist))

28. Give the output of following code: [3]


astr='pInKfloydMONey' yiIkFLloDmNeEe
bstr='' D y
for x in range(len(astr)):
if 'A'<=astr[x]<='M':bstr+=astr[x].lower()
elif 'N'<=astr[x]<='Z':bstr+=astr[x+1]
elif 'a'<=astr[x]<='m':bstr+=astr[x].upper()
elif 'n'<=astr[x]<='z':bstr+= astr[x-1]
print(bstr)
print(min(bstr), max(bstr))
OR
adata={'R':'CAT', 'E':'HAT', 'V':'MAT', 'I':'RAT', 'V':'BAT', 'E':'FAT'}
bdata= 63021, 30655, 66528, 25269, 91728, 42124, 90451
j=-1 {'R': 90451, 'E': 91728,
for k in adata: 'V': 66528, 'I': 63021}
adata[k]=bdata[j] 25269 91728
j-=2
print(adata)
print(min(bdata), max(bdata))

29. Give the output of following code: [3]


mylist=48,56,67,74,95,58
for num in mylist: 90$122$173$212$361$130$
a=num%5
b=num//5
print(a*a+b*b, end='$')
OR
mylist=736,475,973,892,652,586
s, p=0, 1 3$1
for num in mylist: 10$3
d=num//10%10 17$9
s+=d 26$36
p*=d//2 31$72
print(s, p, sep='$') 39$288

30. Write a Python program to in put a floating-point value (say x) and an integer value (say n) and find the sum
of the sequence given below (don't use pow(), ** and math module functions): [3]

Page 4/7
Set-B
Class XI Computer Science Second Term Exam 2022-23 Answer Key
3 5 2 n−1
x x x x
1+ + + +…+
1! 3 ! 5 ! (2n−1)!
x=float(input('Input x? '))
n=int(input('Input n? '))
s, p, f=1, 1/x, 1
for k in range(1, 2*n, 2):
p*=x*x
if k>1: f*=(k-1)*k
s+=p/f
print('Sum=', s)

31. Write a Python program to input an integer and check whether the inputted integer is a Palindrome number
or not. If the inputted integer is a Palindrome number, then display 'Palindrome Number', otherwise display
'Not Palindrome Number'. Don't use str() and slice. [3]
t=n=int(input('Input n? '))
s=0
while t:
d=t%10
s=10*s+d
t//=10
if s==n:
print('Palindrome Number')
else:
print('Not Palindrome Number')

32. Write a Python program to input a positive integer (greater than 1) and check whether the inputted integer
is Prime number or Composite number. If the inputted integer is a Prime number then display 'Prime',
otherwise display 'Composite'. [3]
n=int(input('Input n? ')) n=int(input('Input n? '))
for x in range(2, n//2+1): prime=True
if n%x==0: for x in range(2, n//2+1):
print('Composite') if n%x==0:
break prime=False
else: break
print('Prime') if prime: print('Prime')
else: print('Composite')

33. Write a Python program to input an integer (say n). If inputted value is a positive single digit integer, then
generate and display a triangle as shown below (assuming n is 5). If the inputted value of n is either less
than 1 or greater than 9, then display an appropriate message.
[3]
5
54
543
5432
54321
n=int(input('Input n? ')) n=int(input('Input n? '))
if 1<=n<=9: if 1<=n<=9:
for x in range(n, 0, -1): s=''
for k in range(n, x-1, -1 ): for x in range(n, 0, -1):
print(k, end='') s+=str(x)
print() print(s)
else: else:
print('Input out of Range!') print('Input out of Range!')
OR

Page 5/7
Set-B
Class XI Computer Science Second Term Exam 2022-23 Answer Key
Write a Python program to input two positive integers. Calculate and display HCF of two inputted integers
without using any functions from math module.
x=int(input('1st Integer? '))
y=int(input('2nd Integer? '))
while True:
r=x%y
if r==0:
break
x, y=y, r
print('HCF=',y)

34. Write a Python program to check whether an inputted string is a Palindrome or not. Display "Palindrome" if
the inputted string is Palindrome, otherwise display "Not Palindrome". Don't use any methods from string
object or string slice. [3]
astr=input('Input a String? ') astr=input('Input a String? ')
bstr='' n=len(astr)
for ch in astr: for x in range(n):
bstr=ch+bstr if astr[x]!=astr[-x-1]:
if astr==bstr: print('Not Palindrome')
print('Palindrome') break
else: else:
print('Not Palindrome') print('Palindrome')

SECTION D
35. Write a Python program to input a string. Count and display
 number of words present in the inputted string
 number of words starting with a vowel (ignore case), present in the inputted string
 number of words containing at least 4 characters, present in the inputted string [4]
If the inputted string is 'Second Term Computer Science Exam is on 21st February 2023'
Number of words: 10
Number of words starting with vowel: 3
Number of words containing at least 4 characters: 8
astr=input('Input a String? ')
wlist=astr.split()
c1=c2=c3=0
for word in wlist:
c1+=1
if word[0] in 'AEIOUaeiou': c2+=1
if len(word)>=4: c3+=1
print('Number of Words=', c1)
print('Number of Words starting with vowel=', c2)
print('Number of Words containing at least 4 characters=', c3)

36. Create a list to store n 5-digit random integer values where n is a user inputted value. Find the sum and the
average of elements which does not contain 5. Display the elements, the sum and the average. [4]
If the list contains [67883, 69469, 54420, 39358, 89994, 59405, 10936]
Elements containing 5: 65883, 54420, 39358, 59405
Sum: 67883+69469+89994+10936=238282
Average: 238282/4=59570.5
from random import randint
n=int(input('Number of Elements '))
alist=[randint(10000, 99999) for x in range(n)]
s=c=0
for num in alist:
if '5' not in str(num):
print(num)
Page 6/7
Set-B
Class XI Computer Science Second Term Exam 2022-23 Answer Key
s+=num
c+=1
avg=s/c
print('Sum=', s)
print('Average=', avg)

37. Write a Python program to create a dictionary employee with following keys:
code Employee Code (int)
name Employee Name (str)
bsal Basic Salary (float)
Input Employee Code, Employee Name and Basic Salary from the keyboard during the run-time. Append
two more keys hra and gsal to store House Rent and Gross Salary respectively in the dictionary employee.
House Rent is calculated as:
Basic Salary House Rent
<=100000 15% of Basic Salary
>100000 and <=200000 12.5% of Basic Salary
>200000 and <=400000 10% of Basic Salary
>400000 7.5% of Basic Salary
Gross Salary is calculated as Basic Salary + House Rent. Display the key-value pairs present in the
dictionary using a loop.
[4]
emp= {
'code': int(input('Code? ')),
'name': input('Name? '),
'bsal': float(input('BSal? '))
}
if emp['bsal']<=100000: hra=0.15*emp['bsal']
elif 100000<emp['bsal']<=200000: hra=0.125*emp['bsal']
elif 200000<emp['bsal']<=400000: hra=0.10*emp['bsal']
elif emp['bsal']>400000: hra=0.075*emp['bsal']
emp['hra']=hra
emp['gsal']=emp['bsal']+hra
for key in emp: print(key, emp[key])

Page 7/7

You might also like