12th Cbse Computer Science Dpp 4 q
12th Cbse Computer Science Dpp 4 q
2 Marks 19 x 2 = 38
1) Out of the following, find those identifiers, which cannot be used for naming variables or functions in a
Python program: Total * Tax,While, Class, Switch, 3rd Row, finally, Column () 31, Total.
2) Highlight the literals in the following program and also predict the output. Mention the types of variables
in the program.
a=3
b='l'
c=a-2
d=a-c
e="Kathy"
f='went to party'
g='with Sathy'
print (a,g,e,f,a,g,",",d,g,",",c,g,"and his",e,f)
3) Write the output from the following code:
y = 2000
if (y%4==0):
print ("LeapYear")
else:
print ("Not leap year")
4) Consider the following list 95 79 19 43 52 3
Write the passes of bubble sort sorting the list in ascending order till the 3rd iteration.
5) What are Python modules?
6) What is the use of negative indices in slicing?
7) 17.Write the output of the following code snippet
tup = ( 'geek',)
n=5
for i in range(int(n)):
tup = (tup,)
print(tup)
8) Rewrite the following for loop into while loop:
for a in range(90,9,-9):
print(a)
9) Write a program to find the sum of all digits of the given number.
10) How can we import a module in Python?
11)
Write the corresponding Python expression for the following mathematical expressions:
i) 2-ye2y +4y ii) Iex- x2 - xI
12) What is name resolution rule? Explain it.
13)
Write a void function that receives a 4 digit number and calculates the sum of squares of first two digits
of the number and last two digits of the number egoif 1233 is passed as argument then function should
calculate (12)2+(33)2
14) Explain Scope of Variables.
15) Identify the following function definitions as void or non-void function.
(i) def fun():
print("Hello!")
(ii) def fun():
print("Hello!")
return(1)
(iii) def fun():
print("Hello!")
retum(1)
(iv) def fun():
return(2)
print("Hello")
16) Given a text file car.txt following information of cars carNo, carname, containing mileage. Write a Python
function to display details of all those cars whose mileage is from 100 to 150.
17) Write a function to read the content of a text file "DELHI.txt" and display all those lines on screen, which
are either starting with 'D' or 'M'.
18) Write statements to display the position of the file pointer after reading two lines from a file linked to file
object named fn.
19) Write any two needs for a data file.
3 Marks 4 x 3 = 12
20) How many times will the given loops iterate.
(i) j=0
while (j < 50):
print ("Hello World")
j=j+1
(ii) j=25
while (25< =j< =30):
print ("Temp variable =",j)
j=j+1
(iii) #Assume Boolean variable b is not known.
b= True
sum=0
while b:
sum=sum+5
print (sum)
if (b or not b):
break
21) Write a program that reads three numbers and prints them in ascending order.
22) Write a method in Python to find and display the prime number between 2 to N. Pass N as argument to
the method.
23) A file sports.dat contains information in following formal Event Participant.
Write a function that would read contents from file sports.dat and creates a file named Athletics. dat
copying only those records from sports.dat where the event name is "Athletics"
*****************************************