1.
Which of the following can be used as valid variable identifier(s) in
Python? (2)
(i) 6pri (ii) sum (iii) num# (iv) _goa
Ans. The valid variable identifiers are:
ii) sum iv) _goa
2. Which of the following can be used as valid variable identifier(s) in Python?
(i) 4thSum
(ii) Total
(iii) Number#
(iv) _Data
2
Ans ii) Total iv) _Data
3. Which of the following can be used as valid variable identifier(s) in Python?
(i) 4thSum (ii) Total (iii) Number# (iv) Data
4. i. What is the output of the following code : print 9//2
a. 4 b. 4.5 c. 4.0 d. Error
ii. What is the output of the following program :
i = 0
while i < 3:
print( i )
i++
print (i+1)
(a) 0 2 1 3 2 4 (b) 0 1 2 3 4 5 (c) 1 0 2 4 3 5 (d) Error
5. Which of the following is the use of id() function in python?
(a) id returns the identity of the object
(b) Every object doesn’t have a unique id
(c) Both (a) and (b)
(d) None of the above
Write names of two mutable data types and two immutable data types available in python. 2
Ans Mutable data type: List, Dictionary
Immutable Data type: Tuple, String
Name the python library module which need to be imported to run the following program:
print (sqrt(random.randint(1,16) 1
Ans :math, random
FIND MODULE & FUNCTION OUTPUT QUESTIONS
1) Write the modules that will be required to be imported to execute the following code in Python.
(1)
def main( ):
for i in range (len(string)) ):
if string [i] = = ‘’
print
elif
c=string[i].upper()
print “string is:”c
print “String length=”,len(sring.floor())
Ans.
Math module and String module
2. Name the modules to which the following functions belong: a. uniform() b. fabs() 1
ans a. random() b. math()
3. Name the Python Library modules which need to be imported to
invoke the following functions: (1)
(i) sqrt ( ) (ii) randint ( ) Ans. sqrt:math randint:random
3. Name the Python Library modules which need to be imported to invoke the following functions
(i) floor() (ii)randint()
1
Ans (i)math (ii) random
4. Name the Python Library modules which need to be imported to invoke the
following
functions
(i) floor() (ii) random()
5. Write the modules that will be required to be imported to execute the
following code in
Python.
def main( ):
for i in range (len(string)) ):
if string [i] = = ‘’:
print( )
elif:
c=string[i].upper()
print (“string is:”c)
print (“String length=”,len(sring.floor())
2) Carefully observe the following python code and answer the
questions that follow:
On execution the above code produces the following output.
6
3
Explain the output with respect to the scope of the variables. 2
ans Names declared with global keyword have to be referred at the file level. This is because the
global statement indicates that the particular variable lives in the global scope. If no global statement
is being used, the variable with the local scope is accessed. Hence, in the above code the statement
succeeding the statement global x informs python to increment the global variable x Hence the output
is 6 i.e 5+1 which is also the value for global x. When x is reassigned with the value 3 the local x
hides the global x and hence 3 is printed.
3)