Python Functions and Modules Quiz

Python Functions and Modules Quiz
Python Functions and Modules Quiz


Q1 – If a=[20,30,40,50,60], show the value of a[3].

Q2 – Consider the following code snippet:
1. list = [ [ ] ] * 5
2. list # output?
3. list[0].append(10)
4. list # output?
5. list[1].append(20)
6. list # output?
7. list.append(30)
8. list # output?
Analyse and select the outputs for the lines 2, 4, 6, and 8?

Q3 – Analyse the following code and predict the output.
list1 = [2,4,6,8,10,12,14,16,18,20]
print (list1[0:1],list1[5:7])

Q4 – Create a string with the numbers from 0 to 100, “0123456789101112…”. Choose the correct statement.

Q5 – “The ‘break’ statement can be used to terminate the ‘if’ condition”. State True or False:

Practice Session – Functions

Q1 – Get integer inputs for var1 and var2 from the user.
Dene a function ‘add’, that takes var1 and var2 as arguments and returns its sum (return without parenthesis).
Call the function. Capture the sum in var3 and print.
# variable declaration



# function definition

def add(var1,var2):

return var1+var2

# function call and print result



Practice Session – Module

Q1 – Import sqrt function from math module. Print the square root of 25 using this function.

from math import sqrt


Practice Session – Numpy package

Q1 – Fill up the code to generate and print 15 random integers between 1 to 100.
import numpy as np


Post-Quiz function and modules

Q1 – Veena, a beginner in Python programing has written the code for counting the number of elements in the list. The code that she has written is given below. Analyse and display the output for the given code.
def addItem(listParam):
  listParam += [1]
mylist = [1, 2, 3, 4]
print len(mylist)

Q2 – Analyze the code given below and choose the correct output.
d = lambda p: p * 2
t = lambda p: p * 3
x = 2
x = d(x)
x = t(x)
x = d(x)
print x

Q3 – Identify which of the following methods return a string that represents the present working directory.

Q4 – Describe the process of pickling in Python.

Q5 – Select the right set of functions to sterilize an object hierarchy and to desterilize a data stream respectively.

Q6 – Identify which of the following functions can be used to create a symbolic link.

Q7 – Which of the following functions can be used to read data from a le using a le descriptor?

Q8 – Describe what contains.

Q9 – State what print(os.geteuid()) prints?

Q10 – State what os.close(f) does?

Recommended Posts:

  1. Pythagoras’ Theorem
  2. Lucky Number
  3. Rhythm Composer
  4. Farewell
  5. Time Table Planning

Leave a Comment

Your email address will not be published. Required fields are marked *