83% found this document useful (6 votes)
14K views

Digital Python Intermediate iON LX Async SP Assessment

This document contains a Python assessment with multiple choice questions related to Python concepts like web development, data structures, OOP, APIs, exceptions and more. There are 27 multiple choice questions in total, testing knowledge of topics like list comprehensions, dictionaries, classes, inheritance, exceptions and built-in functions. The questions have multiple possible answers to choose from for each one.

Uploaded by

Sai Gopi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
83% found this document useful (6 votes)
14K views

Digital Python Intermediate iON LX Async SP Assessment

This document contains a Python assessment with multiple choice questions related to Python concepts like web development, data structures, OOP, APIs, exceptions and more. There are 27 multiple choice questions in total, testing knowledge of topics like list comprehensions, dictionaries, classes, inheritance, exceptions and built-in functions. The questions have multiple possible answers to choose from for each one.

Uploaded by

Sai Gopi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Digital : Python_Intermediate_iON LX_Async_&_SP_Assessment - Course ID: 54196

CLP - Python - Generic - SelfPaced - Assessment Only - E2 Batch 1

Question 1

Select the statement which not true about Pythons web development (Choose four)

1. Access-Control-Allow-Origin header value should be set to ‘*’.


2. Need to configure your web server to announce its version details.
3. Python code need to address only the vulnerabilities that are not addressed by firewall
4. Firewall address the vulnerability issues such SQL injection, XSS etc., So , it is not required to
handle in Pythons code

Question 2

Select the right program for the calculation of factorial: (Choose three)

1. def factorial(N)
res = 1
for i in range(1, N+1):
Res *=1
2. def factorial(N)
In N == 1
Return N
else
Return N * fact0(N-1)
3. def factorial(N)
In N == 1
Return N if N == 1
else
Return N * fact1N-1)#

Question 3

Select the correct program to transpose value to key: (Choose two)

1. capitals = {‘United States’: Washington, DC’, ‘France’: ‘Paris’, ‘Italy’: ‘Rome’)


capitals_bycapital = {}
for key, value in capitals.items():
capitals_bycapital.append({capitals [key], key})
2. capitals = {‘United States’: Washington, DC’, ‘France’: ‘Paris’, ‘Italy’: ‘Rome’)
capitals_bycapital = {}
for k,v in capitals.items():
capitals_bycapital[v].append(k)

capital_bycapital
3. capitals = {‘United States’: Washington, DC’, ‘France’: ‘Paris’, ‘Italy’: ‘Rome’)
inverted_dict = {}
for key in capitals:
inverted_dict.setdefault(capitals[key], {]).append(key)
inverted_dict

4. capitals = {‘United States’: Washington, DC’, ‘France’: ‘Paris’, ‘Italy’: ‘Rome’)


capital_bycapital = {capitals[key]: key for in capitals}
capitals_bycapital

Question 4

Which of the following can be used to invoke the __init__ method in X from Y, where Y is a subclass of X
in (in Python 3.x)?(Chosse two)

1. super().__init__()
2. super().__init__(self)
3. X.__init_(self)
4. X.__init__()

Answer:

1. super().__init__()

3.X.__init_(self)

Question 5

What will be the output of the following program?

def country (*abc):

if len(abc) ==1:

item= abc[0]

def f(obj):

rerun obj[item]

else:

def f(obj):

return tuple(obj[item] for item in abc)

return f
selection = []

selection = country(slice(2, None))(‘AUSTRALIA’)

print(selection)

1. USTRALIA
2. ALIA
3. STRALIA
4. AU

Answer: STRALIA

Question 6

See the code below:

import sys

try:

f = open(‘textFile.txt’)

s = f.readline()

I = int(s.strip())

Expect IOError as e:

print(“I/O error({0}); {1}”. format(e.errno, e.strerror))

except ValueError:

print(“Could not convert data to an integer.”)

rasie

except:

print(“Unexpected error:”, sys.exc_info()[0])

finally:

print(“finally excuted…”)

In the code for on ValueError exception there is raise error. Wha is the significance of using ‘raise’.
ValueError exception block?

1. The code will print ValueError print block and exits with an uncaught exception
2. The code will print ValueError print block and exits with an uncaught exception without fianally
bock executed
3. The code will print ValueError print block and exits
4. The code will call except: method and executes the finally block
Question 7

MISSING

Question 8

Which of the following Python?C API functions will NOT always return NULL?

1. PyObject* PyErr_Format (PyObject *exception, const char *format, ...)


2. PyObject*PyErr_SetFromErrWithFilename(PyObject *type, const char *filename)
3. PyObject*PyErr_SetFromWindowsErr(omt ierr)
4. PyObject*PyErr_NewException(Chair *name, PyObject *base, PyObject * dict)
5. PyObject*PyErr_SelfFromErrno(PyObject *type)

Question 9

What is the output of the following code ? (Output values marked by ??)

 def abc(val, y=[[])


y.append(val)
return.y
 abc(3)

??

 abc(4,[1,2])

??

 abc(10)

??

1. [3], [1, 2, 3, 4], [1, 2, 3, 4, 10]


2. [3], [3, 1, 2], [3, 1, 2, 4]
3. [3], [1, 2, 4], [10]
4. [3], [1, 2, 3], [3, 10]

Question 10

Which two of the following dictionary object return “0” on success and “-1” on failure? (Choose two)

1. int PDict_Setlem(PyObject *p, PyObject *key, Object *val)


2. Pyobject *PyDict_GetlemWithErro(PyObject *p, PyObject *key)
3. Pyobject *PyDict_New()
4. int PDict_DelltemShring(PyObject *p, const char *key)

Question 11

Which two techniques can be used to provide polymorphic behavior? (Choose two)

1. Extending a class and overriding an existing method


2. Implementing two class in the same class
3. Extending a class in several different classed
4. Extending a class and adding a new method

Question 12

What is the output of following code in Python 3.x?

class A:

def__ int__(self):

self.calculate(30)

print(“i” in Class A is”, self.i)

def calculate(self, i)

self.i = 2 *i

class B(A):

def__init__self):

super().__init__()

def calculate(self, i):

self.i = 3*i

b = B()

1. “i in Class A is 0”
2. “i in Class A is 60”
3. “i in Class A is 90”
4. Error

Answer: “i in Class A is 60”

Question 13

Select which are NOT characteristic of tuple? (Choose two)


1. The values inside Tuples cannot be sorted
2. The values of tuples can be modified
3. Tuples are immutable
4. List are faster than Tuple

Question 14

Upon creation of the ‘dumbdbm’ database, files with which of the given extension are created?(Choose
two)

1. .dat
2. .dbm
3. .dir
4. .bin

Question 15

Which of the given tuples are not used in the AF_INER6 address family? (Choose three)

1. groups
2. pid
3. port
4. host
5. sockaddr

Question 16

Which of the following datatypes are Hashable? (Choose two)

1. float
2. dictionary
3. set
4. string

Question 17

In Python 3.4, a conventional pluggable event loop model is provided by which of the following library
models?

1. enum
2. asyncio
3. ensurepip
4. selections

Question 18

Which of the following options is a correct syntax of the “AttlistDecHandler” method?

1. AttlistDeclHandler(elname, attname, type, base)


2. AttlistDeclHandler(elname, attname, base, required)
3. AttlistDeclHandler(elname, attname, type, default, required)
4. AttlistDeclHandler(elname, attname, base, default, systemId)

Question 19

What is the output of the following code in Python 3.x environment?

 x = “abcdef”
 I = “i”
 While I in x:
Print(I, end = “ “)
1. Abcdef
2. Error
3. a b c d e f
4. No Output

Question 20

What is the value of variable ‘x’ in the below shown code?

 X = [ i** +1 for I in range(5) ]


1. [0, 1, 4, 9, 16]
2. [0, 1, 2, 3, 4]
3. [1, 2, 5, 10, 17]
4. Error

Question 21

Which of the following Python 3.4.2 shell expression will produce the below-given output?

56.25

1. >>> 7.5#2
2. >>> 7.5^2
3. >>> 7.5 ! 2
4. >>> 7.5**2

Question 22

What will be output of the following program?

i = [12, 9, 14]

k = [7, 16, 11]

for j in i[:]: for m in k[:]:

if (j%m == 0):
j = j //2

m=m/j

print(j.m)

else

j=j+m

m=m–j

pring( j, m)

1. 19-12
35-19
46-36
88
19-8
730
21 -7
34 23
2. 19-12

Question 23

What will be output of the following program?

For i in ranger(1.6):

if i%4 == 0:

print(‘x’)

elif i%2 == 0:

print(‘x’)

else:

print(‘xxxx’)

1. XXXXX
XX
XXXXX
XX
XXXXX
2. XXXXX
X
XXXXXX
X
XXXXX

Question 24

What is the value of variable ‘k’ in the below shown code?

 k = [print(i) for i in ‘hello; if i not in ‘aeiou;]


1. [None, None, None] with Python 3.x
2. [‘h’, ‘l’, ‘l’]
3. [None, None, None] with Python 2.x
4. [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]

Question 25

Which of the following statements are correct? (Choose two)

1. A reference variable is an object


2. An object may contain other objects
3. A reference variable refers to an object
4. An object can contain references to other objects.

Question 26

Which of the following shell expressions in Python 3.4 will give an error?

1. >>> import unicodedata

>>> unicodedata.category(“A”)

2. >>> import unicodedata

>>> unicodedata.decimal(9)

3. >>>import unicodedata

>>> unicodedata.bidirectional(“\u0660”)

4. >>> import unicodedata

>>> unicdedata.name(“/”)

Answer:

import unicodedata

>>> unicodedata.decimal(9)

Question 27
What is the output of the following code?

 Class A:

def__init__(self, x):

self.x = x

x = 44

 Print (a.x)
1. Syntax Error
2. 44
3. 4
4. None of the above

Question 28

As part of the development of a Python module you want to store some user information details into
a table for running SQL query. But you don’t have the privilege to install a new database. You have to
use the feature available with default Python installation.

1. Use Dictionary and write a python program interface to interpret SQL query
2. MySQL is available as default builtin Database. This can be directly used
3. Use File and write a python program interface to interpret SQL query
4. SQL is default builtin Database > This can be directly used

Question 29

Which of the following statements are correct? (Choose two)

1. We cannot use list as a stack in Python 3.4.2


2. Lists in Python 3.4.2 are immutable
3. We can use list as a query in Python 3.4.2.
4. Tuples in Python 3.4.2 are immutable

Question 30

A company uses an offline system orders for selling products. The company wants to build a new online
site. The data trends of the current orders show that customers typically buy once or twice a year. The
company has the following requirements for the site:

1. Should have ability to shop quickly from the application


2. Should have ability for the web designers to modify the users interface to provide a new
user experience
3. There should be ability to browse the catalog and find the product with clicks

What advice would you give this company about the user interface for this application?
1. Write the UI using Ajax accessing Python code
2. Create the UI by mixing HTML and Python code adding libraries
3. Not possible to build such UI requirement in Python
4. Write the UI using Django Framework

Question 31

Select the correct statement about interfacing with other languages from python (Choose four)

1. SWIG is used to interface with interpreted languages


2. Boost.Python provides almost same features of SWIG
3. CPython ctypes library provides support for loading and interfacing with dynamic libraries, such
as DLLS or shared objects at runtime
4. CFFI provides a mechanism for interfacing with C from both PyPy

Question 32

In which of the following modes of files, the ‘tell()’ functions returns an opaque number that gives the
current position of the file object?

1. binary mode
2. text mode
3. both binary and text modes

Answer: text mode

Question 33

What will be the output of the following line of code in Python 3.4.2?

>>> print(0xD + 0xB + 0xC)

1. 0xD0xB0xC
2. 0xD + 0xB + 0xC
3. 0
4. 22
5. 36

Question 34

Which of the following relationship suits best for an Employee and a Person

1. Inheritance
2. Composition
3. None of the above
4. Association

Question 35

Which of the following exceptions is raised when the sequence subscript is out of range?

1. exception UnboundLocalError
2. exception OverflowError
3. exception EOFError
4. exception IndexError

Question 36

Which of the following options is not a server socket method?

1. connect()
2. bind()
3. listen()
4. accept()

Question 37

Which two of the following interface objects cannot have the child nodes? (Choose two)

1. NodeLIst
2. Node
3. ProcessingInstruction
4. Element
5. Comment

Question 38

There is a folder which contains multiple html files. You have to provide a program which will extract the
html keywords from provided files. Select the appropriate Python library which can be used to achieve it.

1. import html.parser
2. import bs4
3. import json
4. import xmltodict

Answer: import bs4

Question 39

Please select the value of after executing the below code. What will be values of var2.

>> > var1=[1, 2, 3]

>> > var2 = var1

>> > var1.append(4)

>> > var2

1. [1, 2, 3, 4]
2. Error
3. Var1
4. [1, 2, 3]

Question 40

What is the output of the following code?

class A:

def __init__(self, i = 0):

self.i = i

class B(A):

def __init__(self, j = 0):

self.j= j

def main():

b = B(50)

print(b, i)

print9b, j)

main()

1. 0 50
2. Attribute Error
3. None of the above

Question 41

A user wants to build a ETL in we which should be able to execute the dynamic rules. Which module in
Python can be used for dynamic rule execution?

1. Use ‘pyregex’ module


2. None
3. Use ‘re’ module
4. Use ‘regex ‘ module

Question 42

A company wants to analyze the receivable and payable for the last 5 years data to identify the
exceptional data. What are the different python functions available to detect outliers?

1. Using boxplot
2. Using regular expression
3. Using django
4. Using histogram
Question 43

What is the output of the following code?

class A:

def __init__(self, x):

self.x =x

>a = A(100)

>a.__dict__[‘y’] = 50

>print(a.x + len(a.__dict__))

1. 102
2. 101
3. 150
4. 100

Question 44

What will be the output of the below given code in Python 3.4.2 shell?

>>>str = “example 123”

>>>str[::-1]

1. example12’
2. 321elpmaxe’
3. Xample123’
4. 3’

Question 45

How do you create a package so that the following reference will work?

p = myxml.objparser.ObjParser()

1. Create a ObjParser.py directory insider the myxml directory


2. Declare the ObjParser packeage in myxml.py
3. Create an__init__.py in the home dir
4. This can not be done
5. Create a __init__.py and objparser.py inside the myxml directory

Answer: Create a __init__.py and objparser.py inside the myxml directory


Question 46

You are building a subsystem that has several complex components, but you want to hide that
complexity from the client code. Which pattern can you apply to hide this complexity?

1. Proxy
2. Façade
3. Decorator
4. Adaptor
5. Bridge

Question 47

What is the output of following code in Python 3.x?

Class A:

def__init__(self):

self.calculate(30)

def calculate(self, i):

self.i = 2 * i

Class B(A):

def__init__(self):

super().__init_()

print(“i in Class B is”, self.i)

def calculate(self, i):

b = B()

1. Error
2. “i in Class B is 90”
3. “i in Class B is 0”
4. “i in Class B is 60”

Question 48

What is the output of the following Code?

>sum([[2,6],[4,3]],[])

1. [0,0]

2. [6,9]
3. [2,6,4,3]

4. None of the above

Question 49

You have been asked to create middleware using Django, Select the correct statements that cab achieved
using middleware (Choose two)

1. Used for creating the Graphical Images


2. Connect to database for CRUD operation
3. Used for user authentication
4. Cross site Script validation can be done

Question 50

Select the connect program for Sum squares from 1 to 10:

1. sum([i**2 for I in range(10)))


2. for I in range(10):

sum=sum+sq(i)

def(sq):

return n*n

3. sum([i**2 for in range(10)])


4. sum( sq(for in in range(10)))
return n*n

Question 51

Select advantages of using Abstract Factory pattern (Choose two)

1. Specifies the types of objects to create using a sample instance


2. Create families of related objects
3. Enforces dependencies between concreate classes
4. Separates the construction of a complex object from its representation
5. Creative whole-part hierarchies

Question 52

What is output of the following code?

class A:

def__init__(self, i = 1):
self.i = i

classB(A):

def__init__(self, j = 2):

self.j= j

def main():

b = B()

print(b.i, b.j)

main()

1. 00
2. 02
3. 01
4. 12

Answer: 4. 1 2

Question 53

What will be output of the following code Snippet. There is no text files called openfile is available

try:

fh = open(“openfile”, “w”)

fh.write(”Write content to file “)

else:

print(“Else condition occurred for “)

finally:

print(“Closing the file”)

fh.close()

1. Program will successfully write the content into openfile and then Print the statement “Close the
file”
2. Raise an exception and in exception “This is Exception” will be printed and the finally block
“Closing the file” will be
3. Fails to Compile

Question 54
You have been given Flight data for analysis. You have to represent the data in graphical representation.
Which are the python library can be used for data visualization? (Choose two)

1. pandas
2. matplotlib
3. scipy
4. pytab
5. ipython

Question 55

Which of the following shell expression will give the result as an integer value?

1. >>> (100 – 4 *5) / (20 – 2 *5)


2. >>> 7.0 / 4
3. >>> 5 / 4
4. >>> 2 * 4 / 2
5. >>> 5 – 2
1. Lines numbers 3 and 5
2. Lines number 5
3. Lines number 1
4. Line number 2

Question 56

You are given assignment to do sentimental analysis on data available in Web. As part of this exercise
you need write program that need to extract data from the website. Please select the appropriate library
for connecting to the sire and extracting the required data from the webpage (Choose two)

1. Import numpy
2. Import bs4
3. Import django
4. Use urlib
5. Import regex

Question 57

During the execution of the below given Python/C API function, what will happen no exception has been
raised int PyErr-ExceptionMatches(PyObject *exc)

1. A memory access violation will occur


2. It will clear the error indicator
3. It will call “void PyErr_Print()” function
4. It will return NULL.

Answer: A memory access violation will occur


Question 58

Select the statements which are not true : (Choose three)

1. os.makedir(“c/temp/newfolder1/newfolder2”) will create subfolder in c:\temp drive


2. os.getcwd() will show the Python installed directory
3. os.link() will create symbolic link
4. print(os.lilstdir()) print directory files in the current directory

Question 59

A company wants to build a web application to support a non-functional requirement (NFR) to process
all requests within 5 seconds. But the customers are complaining that the systems very slow and you
have been contracted to fix the system. The company is not sure whether its customers are meeting the
NFR. What is the most appropriate course of action?

1. Establish measurements, implement the measurements, move the code to production


and determine a go-forward plan
2. Establish measurements, implement the measurements, load test in the test
environment and determine a go-forward plan
3. Add another servers to spread the load across more servers
4. Modify the architecture to implement threading of requests

Question 60

Select the statements which are not true (Choose two)

1. String variable is mutable object


2. List is a mutable object
3. Mutable object cannot be changed

Question 61

Fill in the blank

While working in Python 3.4 sockets are by default created in the ______________________________

1. non –blocking
2. timeout
3. blocking

Answer: blocking

Question 62

What will be output of the following expression in Python 3.4 shell?

‘-6.34’.zfill(7)
1. -006.34’
2. -6.3400’
3. -6.34’
4. -06.340

Answer: '-6.34'.zfill(7)

Question 63

What will be the output of the following code snippert?

class A:

def__init__(self, param):

self.a1 = param

class B(A)

def__init__(self, param):

self.b1 = param

obj = B(100)

print(“% d %d” % (obj.a1, obj.b1))

1. 100 100
2. Error is generated
3. Null Null
4. Null 100

Question 64

You are designing the RDMS access for your current project and deciding which approach is best and
ORM-centric implementation of a client SQL based implementation. Which two statements are
guaranteed to be true in all cased when comparing the two approaches? (Choose two)

1. Any decision must consider and address the issues of performance, scalability, ease of
development, and ACID semantics, weighted according to the specific application being
designed.
2. ORM implementation that do NOT subscribe to an open, standardized API are more difficult to
maintain in the long term
3. ORM is better choice than database connector, because ease of development database
4. Database connector, is a better choice than ORM, because it combines direct access to the
database, a minimal programming model, the best performances and scalability, and ease fo
development

Question 65

What are advantages of JSON over HTTP, as compared to SOAP over HTTP?

1. Strongly typed parameters


2. Smaller message size
3. More security options
4. Guaranteed delivery

Answer: Strongly typed parameters

https://www.techbeamers.com/online-python-quiz-beginners-classes-objects/

https://liveexample-ppe.pearsoncmg.com/selftest/selftestpy?chapter=12

https://quizack.com/python/mcq/this-question-is-based-on-the-graphic-shown-below-consider-the-
python-code-in-figure-1-of-the-given-image-and-choose-its-correct-output-from-figure-2-0-00-b-0-02-c-
this-question-is-based-on-the-graphic-shown-below-in-python-3-4-2-shell-what-will-be-the-output-of-
the-given-code

You might also like