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

XII-CS (Ch. 2 ASSIGNMENT-2)

Uploaded by

sharma20keshav
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)
133 views7 pages

XII-CS (Ch. 2 ASSIGNMENT-2)

Uploaded by

sharma20keshav
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/ 7

DELHI PUBLIC SCHOOL, BAREILLY

XII- Computer Science


ASSIGNMENT-2
(CHAPTER 2 PYTHON REVISION TOUR- II)

Q.1 Consider the following string :

sub = "Computer Science"

What will be the output of the following string operations :

i. print(sub[: :-1])

ii. print(sub[-7:-1])

iii. print(sub[::2])

iv. print(sub[len(sub)-1])

v. print(2*sub)

vi. print(sub[::-2])

vii. print(sub[:3] + sub[3:])

viii. print (sub[ : 8 : -1])

ix. print(sub.startswith('Comp'))

x. print(sub.isalpha())

Q.2 Consider the following string “Adrs”:

Adrs = "WZ-1,New Ganga Nagar, New Delhi"

What will be the output of following string operations :

i. print(Adrs.lower())

ii. print(Adrs.upper())

iii. print(Adrs.count('New'))

iv. print(Adrs.find('New'))

v. print(Adrs.rfind('New'))

vi. print(Adrs.split(','))

vii. print(Adrs.split(' '))

viii. print(Adrs.replace('New','Old'))

ix. print(Adrs.partition(','))

Page 1 of 7
x. print(Adrs.index('Agra'))

(b)
s="welcome2DPS"
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] >= 'n' and s[i] <= 'z'):
m = m +s[i-1]
elif (s[i].isupper()):
m = m + s[i].lower()
else:
m = m +'#'
print(m)

(c)
Find the output of the following code:
Name="PythoN3.1"
R=""
for x in range(len(Name)):
if Name[x].isupper():
R=R+Name[x].lower()
elif Name[x].islower():
R=R+Name[x].upper()
elif Name[x].isdigit():
R=R+Name[x-1]
else:
R=R+"#"
print(R)

Q.4 What will be the output of following program:

a='hello'; b='virat'

for i in range(len(a)):

print(a[i],b[i])

Q.5 What will be the output of the following code segment:


list1 = [1,2,3,4,5,6,7,8,9,10]
for i in range(0,len(list1)):
if i%2 == 0:

Page 2 of 7
print(list1 [i])

Q.6 What will be the output of the following statements?


a) list1 = [12,32,65,26,80,10]
list1.sort()
print(list1)

b) list1 = [12,32,65,26,80,10]
sorted(list1)
print(list1)

c) list1 = [1,2,3,4,5,6,7,8,9,10]
list1[::-2]
list1[:3] + list1[3:]

d) list1 = [1,2,3,4,5]
list1[len(list1)-1]

e) Lst=[„C‟,‟O‟,‟M‟,‟P‟,‟U‟,‟T‟,‟E‟,‟R‟]
print(Lst[3:6])

f) Lst = [ 12, 34, 4, 56, 78, 22, 78, 89]


print(Lst[1:6:2])

g) L = [ 1,2,3,4,5,6,7]
B=L
B[3:5] = 90,34
print(L)

h) colors=["violet", "indigo", "blue", "green", "yellow", "orange", "red"]


del colors[4]
colors.remove("blue")
colors.pop(3)
print(colors)

i) A = [17, 24, 15, 30]


A.insert( 2, 33)
print ( A [-4])

Q.7 Find the output of the following statements:


tup1 = (23,1,45,67,45,9,55,45)
tup2 = (100,200)
Page 3 of 7
i. print(tup1.index(45))
ii. print(tup1.count(45))
iii. print(tup1+ tup2)
iv. print(len(tup2))
v. print(max(tup1))
vi print(min(tup1))
vii. print(sum(tup2))
viii. print(sorted(tup1))
print(tup1)
ix. S = 1, (2,3,4), 5, (6,7)
len(S)
x. T = (2,66,77,55,6,9,55,8)
print(T.index(55))

Q.8 Find the output of the following code:

s="LOST"
L=[10,21,33,4]
D={}
for I in range(len(s)):
if I%2==0:
D[L.pop()]=s[I]
else:
D[L.pop()]=I+3

for K,V in D.items():


print(K,V,sep='*')

Q.3 MCQ:

1. Identify the valid Python statement from the following:


a) a=dict() b) b= { } c) c=[] d) d=dict{ }
2. Which of the following is not a sequential datatype in Python ?
(a) Dictionary (b) String (c) List (d) Tuple
1. Consider the statements given below and then choose the correct output from the
given options:
str=“COMPUTER”
print(str[:4]+”$”+str[-5:])
a) COMP$PUTER b) COMP$UTER c) COMP$RETU d) COMP$RETUP
2. Select the correct output of the code :
S="Amrit Mahotsav @ 75"
A=S.split(" ", 2)
print(A)
a) ('Amrit', 'Mahotsav', '@', '75') b)['Amrit', 'Mahotsav', '@ 75']

Page 4 of 7
c) ('Amrit', 'Mahotsav', '@ 75') d)['Amrit', 'Mahotsav', '@','75']
3. Select the correct output of the code :
x='apple,pear,peach'
y=x.split(',')
print(z)
a) ['apple', 'pear', 'peach'] b) ['pear','apple', 'peach']
c) ['peach','apple', 'pear'] d) 'apple pear peach'
4. For a string S declared as S = 'PYTHON', which of the following is incorrect?
(A) N=len(S) B) T = S (C) 'T' in S (D) S[0] = 'M'
5. Which of the following is/are immutable object types in Python ?
(A) List (B) String (C) Tuple (D) Dictionary
6. What shall be the output for the execution of the following Python Code ?
Cities = ['Delhi', 'Mumbai']
Cities[0], Cities[1] = Cities[1], Cities[0]
print(Cities)
7. Given the dictionary D={'Rno': 1, 'Name':'Suraj'} ,
write the output of print(D('Name')).
Suppose a tuple T is declared as T = (10, 12, 43, 39), which of the following is incorrect?
a) print(T[1]) b) T[2] = -29 c) print(max(T)) d) print(len(T))
8. Identify the valid declaration of L: L = [„Mon‟, „23‟, „hello‟, ‟60.5‟]
a. dictionary b. string c.tuple d. list
9. If the following code is executed, what will be the output of the following code?
name="ComputerSciencewithPython"
print(name[3:10])
10. Given a Tuple tup1= (10, 20, 30, 40, 50, 60, 70, 80, 90).
What will be the output of print (tup1 [3:7:2])?
a. (40,50,60,70,80) b.(40,50,60,70) c.[40,60] d. (40,60)
11. Which of the following operator cannot be used with string data type?
a. + b. in c. * d. /
12. What will be the output of the following code?
tup1 = (1,2,[1,2],3)
tup1[2][1]=3.14
print(tup1)
a. (1,2,[3.14,2],3) b. (1,2,[1,3.14],3)
c. (1,2,[1,2],3.14) d. Error Message
13. What is the correct way to add an element to the end of a list in Python?
a. list.add(element) b. list.append(element)
c. list.insert(element) d. list.extend(element)
14. What will be the output of :
print("Welcome To My Blog"[2:6] + "Welcome To My Blog"[5:9])
a. Lcomme b. lcomme T c. lcomme To d. lcomme
15. Which of the following statement(s) would give an error during the execution of the
following code?
Page 5 of 7
R = {'pno':52,'pname':'Virat', 'expert':['Badminton','Tennis'] ,'score':(77,44)}
print(R) #Statement 1
R['expert'][0]='Cricket' #Statement 2
R['score'][0]=50 #Statement 3
R['pno']=50 #Statement 4
a.Statement 1 b.Statement 2 c.Statement 3 d. Statement 4
16. Given the following dictionaries:
dict_student = {"rno" : "53", "name" : 'Rajveer Singh'}
dict_marks = {"Accts" : 87, "English" : 65}
17. Which statement will append the contents of dict_marks in dict_student?
a. dict_student + dict_marks b. dict_student.add(dict_marks)
c. dict_student.merge(dict_marks) d. dict_student.update(dict_marks)
18. What will be the output of the following code?
L=["One , Two", "Three", "Four"]
print(len(L)/2*len(L[0]))
a. 6.5 b. 13 c. 13.5 d. 6.0
19. What will be the output of the following code?
s=”Python is fun”
l=s.split()
s_new = '-'.join( [l[0].upper() , l[1], l[2].capitalize()] )
print(s_new)
a) Python-is-fun b) PYTHON-Is –Fun
c) PYTHON-IS-Fun d) PYTHON-is-Fun
20. Which of the following will delete key-value pair for key = “Red” from a dictionary D1?
a. delete D1("Red") b. del D1["Red"]
c. del.D1["Red"] d. D1.del["Red"]

21. Consider the statements given below and then choose the correct output from the
given options:
pride="#G20 Presidency"
print(pride[-2:2:-2])
a. ndsr b. ceieP0 c. ceieP d. yndsr
22. Which of the following statement(s) would give an error during execution of the
following code?
tup = (20,30,40,50,80,79)
print(tup) #Statement 1
print(tup[3]+50) #Statement 2
print(max(tup)) #Statement 3
tup[4]=80 #Statement 4
a. Statement 1 b. Statement 2 c. Statement 3 d. Statement 4

23. Given the following Tuple :


Tup= (10, 20, 30, 50)

Page 6 of 7
Which of the following statements will result in an error?
a) print (Tup [0]) b) print (Tup [1:2])
c) Tup.insert (2,3) d) print (len (Tup))

24. Select the correct output of the code:


S= "Amrit Mahotsav @ 75"
A=S.partition (" ")
print (a)
a) ('Amrit Mahotsav', '@','75') b) ['Amrit', 'Mahotsav ','@', '75']
c) ('Amrit', 'Mahotsav @ 75') d) (' it', '', Mahotsav @ 75')

25. ___________function is used to arrange the elements of a list in ascending order.


(a) sort() b) arrange() (c) ascending() (d) asort()

Page 7 of 7

You might also like