[go: up one dir, main page]

0% found this document useful (0 votes)
232 views10 pages

Xii Cs Worksheet - Find Output2 1m

The document contains a worksheet for Class XII Computer Science students, featuring a series of programming tasks and questions related to Python code. Each question requires students to analyze and predict the output of given code snippets, manipulate strings and dictionaries, and perform various operations using Python's built-in functions. The worksheet aims to assess students' understanding of Python programming concepts and their ability to apply them in practical scenarios.

Uploaded by

Mohammed Mishal
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)
232 views10 pages

Xii Cs Worksheet - Find Output2 1m

The document contains a worksheet for Class XII Computer Science students, featuring a series of programming tasks and questions related to Python code. Each question requires students to analyze and predict the output of given code snippets, manipulate strings and dictionaries, and perform various operations using Python's built-in functions. The worksheet aims to assess students' understanding of Python programming concepts and their ability to apply them in practical scenarios.

Uploaded by

Mohammed Mishal
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/ 10

BHARATHI VIDHYALAYA SENIOR SECONDARY SCHOOL

WORK SHEET – FIND OUTPUT (1 MARKS)


CLASS: XII SUBJECT: COMPUTER SCIENCE
FIND THE OUTPUT OF THE FOLLOWING CODE:
ST='IamHere4you'
1. Give output of :
print( ST[-2::-2] )
str="My program is program for you"
2. t = str.partition("program")
print(t)
str="PYTHON@LANGUAGE"
3. print(str[2:12:2])
num1 = input("Enter a number and I'll triple it: ") #num1=8
4. num1 = num1 *3
print(num1)
What will be the output of this code
5. >>>L1=[8,11,20]
>>>L1*3
dict_exam={"Exam":"AISSCE", "Year":2023}
6. dict_result={"Total":500, "Pass_Marks":165}
Which statement will merge the contents of both dictionaries
a = "Year 2022 at All the best"
a = a.split('2')
7. b = a[0] + ". " + a[1] + ". " + a[3]
print (b)
myexam="@@CBSE Examination 2022@@"
8. Write the output of: print(myexam[::-2])
my_dict = {"name": "Aman", "age": 26}
my_dict['age'] = 27
9. my_dict['address'] = "Delhi"
print(my_dict.items())
myTuple = ("John", "Peter", "Vicky")
10. x = "#".join(myTuple)
print(x)
11. print(2**3 + (5 + 6)**(1 + 1))
Consider the string state = “Jharkhand”. Identify the appropriate statement that will display the last five
12. characters of the string state?
if not False:
print(10)
13. else:
print(20)
Str = "Computer"
14. Str = Str[-4:]
print(Str*2)
student = {'rollno':1001, 'name':'Akshay', 'age':17}
15. student['name']= “Abhay”
print(student)
What will be the content of dictionary d after executing the following code
16. d={1:100,2:200}
t=(1:150,3:300}
d.update(t)
s1=”computer”
17. print(s1[-1:-4,-2])
s=”Good Morning”
18. print(s.capitalise( ),s.title( ), end=”!”)
What is the output of the functions shown below?
19. min(max(False,-3,-4),2,7)
What will the following code do?
20. dict={“Phy”:94,”Che”:70,”Bio”:82,”Eng”:95}
dict.update({“Che”:72,”Bio”:80})
a=5
b=10
21. a+=a+b
b*=a+b
print(a,b)
num_list=[“One”,”Two”,”Three”,”Four”]
22. for c in num_list:
print(c)
a="Year2022atallthe best"
a=a.split('a')
23. b=a[0]+"-"+a[1]+"-"+a[3]
print (b)
myexam="RussiaUkrain"
24. Write the output of :
print(myexam[-2:2:-2])
D1={"sname":"Aman","age":26}
D1['age']=27
25. D1['address']="Delhi"
print(D1.items())
26. print(True OR NOT False AND True)
Str=”I will Succeed”
27. lis=str.split(“ “)
print(lis[-1])
28. print(2**3**2//8)
Mystr=”I will win”
29. Write the output of: print(Mystr[2:6])
dictcount={“age1”:26,”age2”:32,”age3”:40}
sum=0
30. for key in dictcount:
sum=sum+dictcount[key]
print(sum)
L=["One , Two", "Three", "Four"]
31. print(len(L)/2*len(L[0]))
Write a suitable Python statement for each of the following tasks using built-in functions/methods only:
32. i To delete an element Mumbai:50 from Dictionary D.
ii To display words in a string S in the form of a list
Write a Python Program to display alternate characters of a string my_str.
33. For example, if my_str = "Computer Science"
The output should be Cmue cec
EXAM="COMPUTER SCIENCE"
34. print(EXAM[:12:-2])
ANIMAL={"dog":10,"tiger":5,"elephant":15,"Cow":3}
35. print("Tiger" not in ANIMAL)
Tuple1=(10,)
36. Tuple2=Tuple1*2
print(Tuple2)
elements=['apple',200,300,'red','blue','grapes']
37. i) print(elements[3:5]) ii) print(elements[::-1])
exam=[‘english’,’physics’,’chemistry’,’cs’,’biology’]
38. i) To insert subject “maths” as last element ii) To display the list in reverse alphabetical order
X="Swatchtha Hi Seva @ Swatcch Bharat"
39. Y=X.split()
print(Y)
What could be the minimum possible and maximum possible numbers generated by following code?
40. import random
print(random.randint(3,10)-3)
a=10
def call():
global a
41. a=15
b=20
print(a)
call()
X={‘Sunil’:190, ‘Raju’:10, ‘Karambir’:72, ‘Jeevan’:115}
42. print(‘Jeevan’ in X, 190 in X, sep=”#”)
a = "Python! is amazing!"
a = a.split('!')
43. b = a[0] + "." + a[1] + "." + a[2]
print (b)
X=”Kendriya Vidyalaya sangathan”
44. Write the output of: print(X[4:9]*2)
hello = {empname: "Ishan", address: ”New Delhi”, salary: 10000}
hello[salary] = 15000
45. hello[address] = "Delhi"
print(hello.keys())
a=tuple()
a=a + tuple(‘Python’)
print(a)
46. print(len(a))
b=(10,20,30)
print(len(b))
Write the Python statement for each of the following tasks:
(i) str="PYTHON@LANGUAGE" To print the above string from index 2 onwards using a single
47. statement.
(ii) To initialize an empty dictionary named as d using BUILT_IN functions/ methods only.
Write the Python statement for each of the following tasks using BUILT_IN functions/methods only:
1+1=2
48. (i) s=”LANGUAGE"
To convert the above string into list.
(ii) To initialize an empty tuple named as t.
dic1={‘r’:’red’,’g’:’green’,’b’:’blue’}
49. for i in dic1:
print (i, end =’ ’)
>>> Str= "BHASHA SANGAM @ 75"
50. >>> S=Str.partition(" ")
>>> print(S)
MN="Bharat @G20"
51. print(MN[-2:2:-2])
x=5
def function1():
global x
y=x+x*2
52. print(y,end=”,”)
x=7
function1()
print(x)
Write the Python statement for each of the following tasks using BUILT-IN
functions/methods only:
53. (i) To insert an element 100 at the Second position, in the list L1.
(ii) To check whether all the characters in the string S1 are digits or not.
Str=“Computer”
54. Str=Str[-4:]
print(Str*2)
mystr = “Hello I am a Human.”
55. print(mystr[::-3])
p=10
q=20
p*=q//3
56. p=q**2
q+=p
print(p,q)
D1={1: “One”,2: “Two”, 3: “C”}
D2={4: “Four”,5: “Five”}
57. D1.update(D2)
print (D1)
Evaluate the expression given below if A=16 and B=15.
58. A % B // A
s=“I#N#F#O#R#M#A#T#I#C#S”
59. L=list(s.split(‘#’))
print(L)
def fun(x):
x[0] = 5
60. return x
g = [10,11,12]
print(fun(g),g)
x = 27
y=9
61. while x < 30 and y < 15:
x=x+1
y=y+1
print(x,y)
62. The value of X is: X = 2+9*((3*12)-8)/10
def check(x,y):
if x != Y:
return x + 5
63. else:
return y +10
print(check(10,5))
D1={"Exam":"ICSCE", "Year":2023, "Total":500}
64. Which statement will add a new value pair (Grade: “A++”) in dictionary D1?
Str = "KENDRIYA VIDYALAYA SANGATHAN JAMMU REGION"
Str = Str.split()
65. NewStr = Str[0] + "#" + Str[1] + "#" + Str[4]
print (NewStr)
Word = "Connect Python”
66. Write the output of: print(Word[: : 3])
dict = {"Item": "Laptop", "Make": "LG" }
dict["Price"] = 57000
67. dict["Make"] = "DELL"
for k in dict:
print(k, ‘@’, dict[k])
Create the dictionary on data
Exam=”PB”
68. Year=”2013”
Where exam and year are keys
69. print('KV Sangathan'.split('an'))
Evaluate the following expressions:
70. (a) 5 // 10 * 9 % 3 ** 8 + 8 – 4
(b) 65 > 55 or not 8 < 5 and 0 != 55
d={"Rohan":67,"Ahasham":78,"naman":89,"pranav":79}
print(d)
sum=0
71. for i in d:
sum+=d[i]
print(sum)
print("sum of values of dictionaries",sum)
Str1=”Hello World”
72. str1.replace('o','*')
print(str)
name="Kendriya Vidyalaya Sangathan"
73. print(name[2:13:2])
mystr = ‘Python programming is fun!’
74. mystr = mystr.partition(‘pro’)
mystr=’$’.join(mystr)
Convert the following for loop into while loop:
name = ‘ Karim Benzema’
75. for index in range(len(name)):
print(name[index].upper(),end=’’)
76. Marks = {‘Sidhi’:65,’Prakul’:62,’Suchitra’:64,’Prashant’:50}
newMarks = {‘Suchitra’:66,’Arun’:55,’Prashant’:49}
Marks.update(newMarks)
for key,value in Marks.items():
print(key,’scored’,value,’marks in Pre Board’,end= ‘ ‘)
if(value<55):
print(‘and needs imporovement’end=’.’)
print()
Data = ["P",20,"R",10,"S",30]
Times = 0
Alpha = ""
Add = 0
77. for C in range(1,6,2):
Times = Times + C
Alpha = Alpha + Data[C-1]+"$"
Add = Add + Data[C]
print (Times,Add,Alpha)
names = [‘Hasan’,’Balwant’,’Sean’,’Dia’]
78. print(names[-1][-1])
State weather True or False:
79. “The expression 2**2**3 is evaluated as (2**2)**3.
80. print(16 - (4 + 2) * 5 + 2**3 * 4)
name="IlovemyCountry"
81. print(name[3:10])
mystring = “Pynative”
stringList = [ “abc”, “Pynative”,”xyz”]
82. print(stringList[1] == mystring)
print(stringList[1] is mystring)
D1={“John”:40 , “Peter” : 45}
83. D2= { “John”: 466, “Peter” : 45}
Print(D1>D2)
Write a python command to create list of keys from a dictionary.
84. dict={‘a’:’A’, ‘b’:’B’, ‘c’:’C’, ‘d’:’D’}
85. prinr(10 > 5 and 7 > 12 or not 18 > 3)
mystr1 = ‘Sequence with labels’
86. mystr2 = ‘$’
print(mystr2*6+mystr1+mystr2*5)
init_tuple_a =( 'a', '3’)
87. init_tuple_b = ('sum', '4')
print (init_tuple_a + init_tuple_b)
T1= ( )
88. T2=T1 * 2
print(len(T2))
Lib={“Novel”:152,”Magzine”:20,”Newspaper”:10,”Books”:250}
89. Write Python statement to delete key:value pair for key=”Novels”.
Mydict={}
Mydict[(1,2,3)]=12
Mydict[(4,5,6)]=20
90. Mydict[(1,2)]=25
total=0
for i in Mydict:
total=total+Mydict[i]
print(total)
print(Mydict)
SS="PYTHON"
91. print( SS[:3:])
A Python List is declared as Stud_Name = ['Aditya', 'aman', 'Aditi','abhay']
92. What will be the value of min(Stud_Name)?
Tup=(100)
93. print(Tup*3)
line="T-20 Cricket World Cup 2022"
94. x=line[::-1]
print(a[0:4:1][::-1])
India={"Animal":"Tiger","Bird":"Peacock","Flag":"Tri-Color"}
95. India["Capital"]="New Delhi"
print(India.values())
Identify the key and values from the dictionary given below?
96. D = {“Rohan”:{“Manager”:427, “SBI”, 05884 } }
num = 7
def func ( ) :
97. num = 27
print(num)
m= (8>9 and 12>3 or not 6>8)
98. print(m)
T= [“20”, “50”, “30”, “40”]
Counter=3
Total= 0
for I in [7,5,4,6]:
99. newT=T[Counter]
Total= float (newT) + I
print(Total)
Counter=Counter-1
Identify the data type of X:
100. X = tuple(list( (1,2,3,4,5) ) )
d={'amit':19,'vishal':20}
101. print(d.keys())
102. What will be the output of: print (10>20)?
Write the steps to perform an Insert query in database connectivity application. Table ‘student’ values are
103. rollno, name, age (1,’AMIT’,22)
104. print([x+y for x in 'ball' for y in 'boy'] )
d={1:100,2:200}
105. for x,y in d:
print(x*y, end=’’#”)
l=[1,2,5,6,7,9,10,22,38]
106. k=[e1*r for e1 in l if (e1-4)>1 for r in l[:4]]
print(k)
107. Given the lists L=[1,3,6,82,5,7,11,92],the output of print(L[2:5])is
marks = {"Ashok":98.6, "Ramesh":95.5}
108. print(list(marks.keys()))
109. print(75.0 / 4 + (2** 3))
110. L=[4,3,6,8,2]
Lst=[]
for i in range(len(L)):
if L[i]%2==0:
t=(L[i],L[i]**2)
Lst.append(t)
print(Lst)
a = [0, 1, 2, 3]
111. del a[:]
print(a)
a=[1,2,3,4]
112. b=[sum(a[0:x+1]) for x in range(0,len(a))]
print (b)
data = [1,2,4,5]
for x in data:
113. x = x + 10
print(data)
a=[1,2,3,4,5]
for i in range(1,5):
114. a[i-1]=a[i]
for i in range(0,5):
print(a[i],end=" ")
l=[1,2,3,4,5]
115. l[1:2]=[7,8]
print(l)
Given tp = (1,2,3,4,5,6). Which of the following two statements will give the same output?
116. 1. print(tp[:-1]) 2. print(tp[0:5]) 3. print(tp[0:4]) 4. print(tp[-4:])
test_list = [5, 6, 7]
test_tup = (9, 10)
117. res = tuple(list(test_tup) + test_list)
print(str(res))
118. Given an object L=[[1,2,3],4,5, [6,7,8]] What will be the output of print (L[3][1]])?
L= [1,3,5,4,8,9]
119. print(L[-1:-5])
lst=[2,4,6,8,10]
for i in range(1,5):
120. lst[i-1]=lst[i]
for i in range(0,5):
print(lst[i],end=' ')
121. print (5+2**6<9+2-16//8)
122. print(4 + 3**3/2)
LST= [[22.0, 51.6, 22.8],[23.0, 44.0, 15.0]]
123. L = LST[-2][2]
print(L)
for i in range(1,3):
124. print('answer ',i,'is', i**2)
125. print( float(5+int(4.39+2.1)%2))
126. print(15.0 / 4 + (8 + 3.0))
127. print ((30.0 // 4 + (8 + 3.0))
128. print(15.0/4+(8*3.0))
129. L=[ x**2 for x in range(3,5)]
print(L)
d1={1:2,3:4,5:6}
130. d2=d1.popitem()
print(d2)
131. print("Welcome To My Blog"[2:6] + "Welcome To My Blog"[5:9])
132. A tuple is declared as T = (20,5,16,29,83) What will be the problem with the code T[1]=100
133. print(20//3*2+(35//7.0))
x=10.0
134. y=(x<100.0) and x>=10
tp1=(10,15,20,60)
135. tp1=tp1+(3)
print(tp1)
T=(10,20,[30,40,50],60,70)
136. T[2][1]=100
print(T)
mylist = [2,14,54,22,17]
tup = tuple(mylist)
137. for i in tup:
print(i%3, end=",")
squares = {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
138. print(squares.pop(4))
L1=[11,23,16,28,55,37,61,89]
139. write the output of the code given below :
print(L1[-3:8])
L=[1,4,9,16,35,27]
140. l=[num/3 for num in L if num%3==0]
print(l)
data = [20,19,19,17,20,19,17,20]
d = {}
for x in data:
if x in d:
141. d[x]=d[x]+1
else:
d[x]=1
print(d)
Tup1=(10,15,20,25,30)
142. print(Tup1[-1:0:-2])
lst1=[10,15,20,25,30]
lst1.insert(3,4)
143. lst1.insert(2,3)
print(lis[-5])
list= [10, 20, 30, 40, 50, 60, 70, 80]
144. print(list[ : : 2])
List1=[10,[20,30,40],50,60,70,80,90]
145. What will be the output of print (List1[1:3:2])?
tup1=(10,20,30,40,50,60,70,80,90).
146. What will be the output of print(tup1[3:7:2])?
Suppose a tuple T is declared as T = (10, 20, 30, 40),
147. what will be the output of print(T*2)
148. tuple1 = (10,12,14,16,18,20,22,24,30)
print( tuple1[5:7] )
tuple1 = (11,22,33,44,55,66)
list1 =list(tuple1)
new_list = []
for i in list1:
149. if i%2==0 :
new_list.append(i)
new_tuple = tuple(new_list)
print(new_tuple)
L1, L2 = [10, 23, 36, 45, 78], [ ]
for i in range :
150. L2.insert(i, L1.pop( ) )
print( L1, L2, sep=’@’)
151. print(51+4-3**3//19-3)
152. print (10*1*2**4-4//4 )
153. Evaluate 6 * 3 + 4 ** 2 // 5 – 8
k= 7 + 3 **2 * 5 // 8 – 3
154. print(k)
155. print(4+2**3**2-55//11%3)
s = “Bring it on”
l = s.split()
156. s_new = “#”.join([l[0].lower(), l[1], l[2].title()])
print(s_new)
text = “This is a string literal”
157. print(text[-2:3:-2])
What is the minimum, maximum value that can be obtained by the variable
lottery when the following code is executed?
import random
158. seed = random.random()
lottery = seed + random.randint(1,3)
a) 1, 3.9999 b) 1, 4 c) 0, 3.9999 d) 0, 2.9999
Write the python statement for each of the following tasks using BUILT-IN functions/methods only:
159. (i) To remove an element at index 2 in a list L
(ii) To check whether a string named text has ‘th’ in the beginning.
Write the python statement to import the required module and (using built-in function) to perform
following tasks
160. (i) To calculate the cosine of variable angle
(ii) To calculate the absolute value of variable num

***************************

You might also like