PM SHRI KV NO3 BHUBANESWAR
HOLIDAY HW(WINTER BREAK)
विषय / SUB – Computer Science (083)
Q. NO QUESTION
1 State True or False:
“In a Python program, if a break statement is given in a nested loop, it terminates
the execution of all loops in one go.”
2 What will be the output of the following statement:
print(3-2**2**3+99/11)
a. 244 b. 244.0 c. -244.0 d. Error
3 Which of the following statement(s) would give an error after executing the
following code?
D={'rno':32,'name':'MsArchana','subject':['hindi','english','cs'],
'marks': (85,75,89)} #S1
print(D) #S2
D['subject'][2]='IP' #S3
D['marks'][2]=80 #S4
print(D) #S5
(A) S1 (B) S3 (C) S4 (D) S3 and S4
4 Which statement is not valid in Python:
a. t = 1 b. t = ‘1’ c. 1 = t d. 1 == ‘1’
5 Mention the datatype of a where a=1 + 1.5:
a. tuple b. int c. string d. float
6 Evaluate following expression:
14/2%3+16**2//5*2-5
7 What will be the datatype of d, if d = (15) ?
(a) int (b) tuple (c) list (d) string
8 What will be the output of the following code:
print(‘India’[-2])
a. n b. In c. i d. ia
9 Which of the following is not an arithmetic operator:
a. + b. ! c. * d. %
10 What will be the output of following code:
print('Hi','Bye', sep='#',end ="%" )
a. Hi Bye b. Hi Bye% c. Hi%Bye# d. Hi#Bye%
11 Function range(2,4) will yield an iterable sequence like
a. [1,2,3,4] b. [2,3,4] c. [2,3] d. [3,4]
12 Predict the output.
marks = {"Ashok":98.6, "Ramesh":95.5}
print(list(marks.keys()))
(a) ‘Ashok’, ‘Ramesh’ (b) 98.6, 95.5 (c) [‘Ashok’,’Ramesh’] (d) (‘Ashok’,’Ramesh’)
13 Given the following dictionaries
dict_fruit={"Kiwi":"Brown", "Cherry":"Red"}
dict_vegetable={"Tomato":"Red", "Brinjal":"Purple"}
Which statement will merge the contents of both dictionaries?
(a) dict_fruit.update(dict_vegetable) (b) dict_fruit + dict_vegetable
(c) dict_fruit.add(dict_vegetable) (d) dict_fruit.merge(dict_vegetable)
14 Given a List L1 = [‘Andhra Pradesh’, ‘Maharashtra’, ‘Rajasthan’]. Find the output of
the following statement
print(L1[1][2:-2])
a. harasht b. harashtr c. arashtr d. arasht
15 Which method/function is used to break a String sentence into a List of Words?
a. join() b. list() c. split() d. len()
16 Select the correct output of the code:
count=0
while(True):
if count%3 == 0:
print(count, end=” ”)
if (count>15):
break
count+=1
(a) 0 1 2 ….. 15 (b)Infinite loop (c) 0 3 6 9 12 15 (d) 0 3 6 9 12
17 Predict the output of the Python code given below:
T = (9,18,27,36,45,54)
L=list(T)
L1 = []
for i in L:
if i%6==0:
L1.append(i)
T1 = tuple(L1)
print(T1)
Or
Write a program to create a dictionary from a string.
Sample string: ‘w3resource’
Expected output: {'3': 1, 's': 1, 'r': 2, 'u': 1, 'w': 1, 'c': 1, 'e': 2, 'o': 1}
18 (a)Given is a Python string declaration:
Str1="**JEE Examination 2023**"
Write the output of: print(Str1[::-1])
(b)Write the output of the code given below:
D1 ={"sname":"irya", "age": 2}
D1['age']=8
D1['address']= "MP"
print(D1.items())
19 L= [3,1,2,3,4,5,3,6,7,8] is a list in python.
(i) Write a Python statement to arrange the list elements in descending order in
the list itself.
(ii) Write a Python statement to insert 9 after 8 in the given list.
20 What is the output produced by the following code?
21 Consider the lists L1=[1,2,3] and L2=[5,6,7]. What will be output of the following‐
(i) L1*2 (ii) L1+L2
OR
Consider a list L=[10,12,14,20,22,24,30,32,34], find the output of the
following‐
(i) L[ 0: 10 : 2] (ii) L[ : : 3]
22 Rewrite the following code in Python after removing all syntax error(s).
30 = To
for K in range(0, To)
If K%4 == 0:
print(K*4)
else:
Print(K + 3)
23 Write a program to add and display twice of odd values from the list of Nums.
For example :
If the Nums contains [25,24,35,20,32,41]
The program should display
Twice of Odd Sum: 202
24 Write a program to print the following pattern of n lines.
Value of n taken as input.
Sample output:
Enter number of lines: 4
1=1
1+2=3
1+2+3=6
1+2+3+4=10
25 Write a python program that takes a string as an input and prints a list containing
length of each word of a string.
For example, if the string is "Come let us have some fun", the list will have [4, 3, 2,
4, 4, 3]
26 Write a program that divides a given tuple into two parts and prints two
separate tuples containing even and odd values of the given tuple.
For example :
If the given tuple contains (25,24,35,20,32,41) the output of program would
be
Odd values: (25,35,41)
Even values:(24,20,32)
27 Consider the following code:
str=input("Enter a String")
while len(str)<=4:
if str[-1]=='z':
str=str[0:3]+'c'
elif 'a' in str:
str=str[0]+'b'
elif not int(str[0]):
str='1'+str[1:]+'z'
else:
str=str+'*'
print(str)
What will be the output produced if the input is:
i. 1bzz
ii. 1a
iii. 0xy
iv. 0yz
v. 5bc
28 Write a Python program to enter a string from the user and perform the following
tasks and print the result after all operations:
(i) Count the number of digits present in the string
(ii) Count the number of # and $ present in the string
29 Write a Program in Python to take a number as input from the user and print
whether the entered number is ‘Prime’ or ‘Not Prime’.
30 Write the output of the following Python code:-
z= [1, [3, 2], [[5, 4, 6], 7], 8]
print(z[z[0]][z[0]])
print(z[z[1][1]+z[0]])
print(len(z[2]))
31 L=“If you can dream it, you can do it.”
Consider the string and write the output of the following Python statements:
(a) print(L[3:])
(b) print(L[1:-1])
(c) print(L.isdigit()) OR (c) print(L*2)
(d) print(L.split())
32 Priya wants to find all the numbers in the Fibonacci Series up to a upper limit
number inserted by the user. (A Fibonacci Series is a series of numbers where
every number in the Series will be the sum of the previous two numbers in the
Series.) She wrote the following code. However, the code has some missing lines
of code. Fill in the missing lines based on the given instructions to help Priya
achieve the required task.
num = __________________________ #Statement1
Fib = [0,1]
for i in ______________________ : #Statement 2
a0 = Fib[i-2]
a1 = ___________ #Statement 3
a2 = ___________ #Statement 4
Fib._____________(a2) #Statement 5
print(Fib)
(i) Statement 1: Python Statement to take input from the user.
(ii) Statement 2: Python statement to create the proper range on which
the loop will run.
(iii) Statement 3: Python Statement to Store the previous number in the
variable a1
(iv) Statement 4: Python Statement to calculate the current number in a2.
(v) Statement 5: Python statement to add the number a2 at the end of
the list Fib.
33 i. Find the output of the Python Code Snippet.
Text1="DIGITAL INDIA2023"
Text2=""
I=0
while I < len(Text1):
if Text1[I]>="0" and Text1[I]<="9":
Val = int(Text1[I])
Val = Val + 1
Text2=Text2 + str(Val)
elif Text1[I]>="A" and Text1[I] <="Z":
Text2=Text2 + (Text1[I+1])
else:
Text2=Text2 + "*"
I=I+1
print (Text2)
ii. Given a Python Code Snippet
str = input("Enter the string: ")
length = len(str)
for a in range(0, length, 2):
print(str[a:a+2])
What will be the output if the entered string is “India is Beautiful”.
34 Your Computer Science teacher has created a list :-
L = [150,50,99,73,14,10,22,46,3,10,60,50,10]
She wants you to use the Built in Methods of List to find the following tasks:-
i. Find the number of times 10 is written in the List L
ii. Find the Maximum Number from the List L
iii. Add all the numbers in the List and Print the total
iv. Arrange the List in Assending Order.
v. Delete the first occurrence of 50 in the List.