11CS T2 2022 23SetAMS

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

Set-A

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


SECTION A
1. Identify the option that contains only Python's fundamental data types. [1]
a) int, float, str, bool
b) list, int, bool, float
c) str, tuple, list, dict
d) int, dict, float, str

2. Identify the option which contains only built-in functions. [1]


a) len(), print(), sort(), eval()
b) eval(), sorted(), type(), id()
c) update(), count(), sum(), max()
d) min(), id(), index(), type()

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


a) True, False, Pass, None
b) Break, Pass, For, While
c) as, in, import, elif
d) TRUE, FALSE, PASS, NONE

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

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


astr="REPUBLIC"
print(astr[2:]*astr.index('PUB'))
a) PUBLICPUBLIC
b) REPUBLICREPUBLIC
c) PUBPUBPUB
d) PUBLICPUBLICPUBLIC

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


data=[10,20,30]
a) data+=(40,50)
b) data+=60,70
c) print(data+(80,90))
d) data*=2

7. Evaluate the expression: 'EARTH' and 245.7 or 42153 [1]


a) 42153 b) 245.7 c) 'EARTH' d) EARTH

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


a) 7 b) 17 c) 8 d) 6

9. Select the correct output. [1]


word="PYTHONCODE"
word=word.partition('ON')
print(word[-1], word[-2], word[-3], sep='->')
a) PYTH->ON->CODE
b) ON->CODE->PYTH
c) CODE->PYTH->ON
d) CODE->ON->PYTH
Page 1/7
Set-A
Class XI Computer Science Second Term Exam 2022-23 Answer Key
10. Select the correct output. [1]
alist=[50,20,30,60,10,40]
del alist[2], alist[3]
print(sum(alist))
a) 160 b) 170 c) 130 d) 210

11. Identify the statement that will not append 66 to the list. [1]
alist=[11,22,33,44,55]
a) alist.append(66)
b) alist.insert(5,66)
c) alist+=[66]
d) alist+=66

12. print(round(45237.25, -3)) will display [1]


a) 45270.0 b) 45000.0 c) 45200.0 d) 45237.0

13. Identify the correct output. [1]

fruit={"apple":"gold", "guava":"green", "grape":"red"}


check="red" in fruit
print(check)
a) True b) Error c) None d) False

14. Identify the correct output. [1]


astr='WIKIPEDIA'
alist=astr.split('I')
print(max(alist)+min(alist))
a) PK b) KP c) WA d) AW

15. Identify the correct output. [1]


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

16. Identify the correct output. [1]


x=['BASIC', 'COBOL', 'PASCAL']
y=','.join(x)
print(y)
a) ,BASIC,COBOL,PASCAL,
b) BASIC,COBOL,PASCAL,
c) BASIC,COBOL,PASCAL
d) ,BASIC,COBOL,PASCAL

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): T=10, 20, 30 is valid tuple declaration. del T is valid but del T[1] is invalid.
Reasoning(R): del can delete any object but can't delete an element from a tuple. Ans: 17. a) [1]

18. Assertion (A): None, True and False are keywords.


Reasoning (R): Python keyword cannot be used as an identifier. Ans: 18. b) [1]

Page 2/7
Set-A
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*IS-NOT+FUNNY'
print(python[2:-6:2]) TO*SNT
print(python[-6:2:-2]) +O-INH

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
Possible correct outputs:
alist=[11,33,55,77,22,44,66,88]
c) 77#22#44#66# d) 33#55#77#22#
start=randint(1,4)
for k in range(start, start+4): Max: 4 Min: 1
print(alist[k], end='#')
a) 33#55#77#22 b) 77#22#44#66 c) 77#22#44#66# d) 33#55#77#22#

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, 1 s=0
while True: for k in range(1, n+1):
s+=2*k-1 s+=2*k-1
if k==n: 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: 100

22. Identify the type of token form the list given below: [2]
a) sum() b) for c) () d) **
Identifier Keyword Delimiter Operator

23. Write two differences between list and tuple data type. [2]
List Tuple
 Mutable type  Immutable type
 A list can be updated  Tuple cannot be updated
 List element can be deleted  Tuple element cannot be deleted
 Enclosed within pair of []  Enclosed within pair of ()

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 run-time error. [2]
Run-time error: Syntactically correct Python statement performs an illegal operation since it encounters an
unexpected data during the program execution. Program comes to an abnormal halt. Example: division by
zero, square root of negative number and logarithm of zero or negative number.

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.
Page 3/7
Set-A
Class XI Computer Science Second Term Exam 2022-23 Answer Key
print(x, end=' ') for x in range(1,11):
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 randrange from random import randrange
nlist={} nlist=[]
for x in range(50): for x in range(50):
num=randrange(10:51) num=randrange(10,51)
nlist.extend(num) nlist.append(num) #nlist+=[num]
while nlist: while nlist:
print(nlist.popitem()) print(nlist.pop())

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


astr='pinkFLOYDTiMe' eIiKflYDdiImE
bstr='' D m
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={'S':52, 'E':75, 'R':46, 'V':15, 'E':34, 'R':29}
bdata='ROCKS', 'EATEN', 'RAISE', 'VOICE', 'EAGLE', 'ROSES', 'SOLID'
j=0 {'S': 'ROCKS', 'E': 'RAISE',
for k in adata: 'R': 'EAGLE', 'V': 'SOLID'}
adata[k]=bdata[j] EAGLE VOICE
j+=2
print(adata)
print(min(bdata), max(bdata))

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


mylist=63,54,73,49,96,86
153$116$205$97$362$290$
for num in mylist:
a=num%5
b=num//5
print(a*a+b*b, end='$')
OR
mylist=643,574,793,439,966,856 4$2
s, p=0, 1 11$6
for num in mylist: 20$24
d=num//10%10 23$24
s+=d 29$72
p*=d//2 34$144
print(s, p, sep='$')

30. Write a Python program to input 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-A
Class XI Computer Science Second Term Exam 2022-23 Answer Key
2 4 6 2n
x x x x
1+ + + +…+
2! 4 ! 6 ! (2 n)!
x=float(input('Input x? '))
n=int(input('Input n? '))
s=p=f=1
for k in range(2, 2*n+1, 2):
p*=x*x
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 an Armstrong number
or not. If the inputted integer is an Armstrong number, then display 'Armstrong Number', otherwise display
'Not Armstrong Number'. [3]
t=n=int(input('Input n? '))
s, p=0, len(str(n))
while t:
d=t%10
s+=d**p
t//=10
if s==n:
print('Armstrong Number')
else:
print('Not Armstrong 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]
1
12
123
1234
12345
n=int(input('Input n? ')) n=int(input('Input n? '))
if 1<=n<=9: if 1<=n<=9:
for x in range(1, n+1): s=''
for k in range(1, x+1): for x in range(1, n+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-A
Class XI Computer Science Second Term Exam 2022-23 Answer Key
Write a Python program to input two positive integers. Calculate and display LCM of two inputted integers
without using any functions from math module.
x=int(input('1st Integer? '))
y=int(input('2nd Integer? '))
p=x*y
while True:
r=x%y
if r==0: break
x, y=y, r
print('LCM=',p//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 consonant (ignore case), present in the inputted string
 number of words containing at most 6 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 consonants: 5
Number of words containing at most 6 characters: 7
astr=input('Input a String? ')
wlist=astr.split()
c1=c2=c3=0
for word in wlist:
c1+=1
if word[0].isalpha() and word[0] not in 'AEIOUaeiou': c2+=1
if len(word)<=6: c3+=1
print('Number of Words=', c1)
print('Number of Words starting with consonant=', c2)
print('Number of Words containing at most 6 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 contain 5. Display the elements, the sum and the average. [4]
If the list contains [65883, 69469, 54420, 39358, 89994, 59405, 10936]
Elements containing 5: 65883, 54420, 39358, 59405
Sum: 65883+54420+39358+59405=219066
Average: 219066/4=54766.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' in str(num):
print(num)
Page 6/7
Set-A
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 10% of Basic Salary
>100000 and <=200000 8% of Basic Salary
>200000 and <=400000 5% of Basic Salary
>400000 3% 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.10*emp['bsal']
elif 100000<emp['bsal']<=200000: hra=0.08*emp['bsal']
elif 200000<emp['bsal']<=400000: hra=0.05*emp['bsal']
elif emp['bsal']>400000: hra=0.03*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