Python Objective 3

Question: Which of these functions can be invoked from a Response object to raise an exception in case of an unsuccessful request?

throw_error()

throw_exception()

raise_for_status()

raise_exception()

Ans:- raise_for_status()

Question: Object pooling can be thought of as a more general purpose implementation of which pattern?

The Factory method design pattern

The Singleton pattern

The Builder pattern

The Strategy pattern

Ans:- The Singleton pattern

Question: The class which is the object pool i.e. holds the pool of instances available should be implemented using which design pattern?

The Singleton pattern

The Factory method design pattern

The Strategy pattern

The Builder pattern

Ans:- The Singleton pattern

Question: While using the new() function to initialize a Singleton, if you want your object to be initialized only once and not each time new() is invoked what would you do?

Throw an error in the __init__() special method

Initialize the object the first time it is created in the __new__() special method

Use the __init__() special method to initialize the object

There is no way to prevent multiple initializations of an object

Ans:- Initialize the object the first time it is created in the __new__() special method

Question: Which of these socket operations is taken care of by Python’s context manager?

Binding the socket to an address

Configuring the socket to use TCP

Closing the socket once it is not required

Sending and receiving data

Ans:- Closing the socket once it is not required

Question: You would like to efficiently iterate over all cells in a 5×5 range, scanning horizontally, and without reading any cell metadata. How would you do this?

Iter_cols

Iter_rows with metadata_only = False

Iter_rows with values_only = True

Iter_rows

Ans:- Iter_rows with values_only = True

Question: Which is true of the abstract factory design pattern?

Is closely related to the factory method pattern

Results in bulky interfaces making them hard to use

Is a structural design pattern as well as a creational design pattern

Instantiates a family of related objects

Ans:-

Is closely related to the factory method pattern

Instantiates a family of related objects

Question: Which of the following is a reason to use the Object Pool design pattern?

Allow only a limited number of instances to be in existence

Apply different strategies for instance creation

Recycle instances rather than re-create instances

Separate object representation from construction

Ans:-

Allow only a limited number of instances to be in existence

Recycle instances rather than re-create instances

Question: How would you find the smallest range within a spreadsheet that actually contains data?

Use iter_cols to iterate over all rows and find those that contain data

Use the calculate_dimension() method of the worksheet object

Use iter_rows to iterate over all rows and find those that contain data

Use the .active method of the worksheet object

Ans:-Use the calculate_dimension() method of the worksheet object

Question: What data structure in Python is most suitable for working with JSON data?

Numpy matrix

Pandas dataframe

Dictionary of nested columns

Dictionary of nested dictionaries

Ans:- Dictionary of nested dictionaries

Question: Which of the following statements is true?

The abstract factory creates families of related objects

The factory pattern is a creational design pattern

The abstract factory pattern creates multiple objects by evaluating input parameters

The abstract factory is a structural design pattern

The factory pattern creates multiple objects by evaluating input parameters

Ans:-

The abstract factory creates families of related objects

The factory pattern is a creational design pattern

The factory pattern creates multiple objects by evaluating input parameters

Question: Which statement is NOT true about the factory method?

Cannot be used to instantiate derived classes of the same base class

Abstracts the creation of a class from how it is used

Evaluates arguments to determine which class to create

Is a creational design pattern

Ans:- Cannot be used to instantiate derived classes of the same base class

Question: If you want the factory method to be abstracted from how each class is instantiated, which of the following is a valid technique to achieve this?

It is not possible to abstract the factory method from how the class is created

Have each class register a creation function with factory method

Use the abstract factory design pattern

Use the singleton design pattern

Ans:- Have each class register a creation function with factory method

Question: What is the type of data which must be sent over a socket connection?

string

bytes

float

int

Ans:- bytes

Question: Which of the following are use cases for the Proxy pattern?

Making it easy to add functionality at runtime

Validating parameters for access to the real subject

Checking whether client access is authenticated

Allowing undo functionality for operations

Ans:-

Validating parameters for access to the real subject

Checking whether client access is authenticated

Question: While implementing a decorator, which of the following is true?

A decorator knows the inner implementation of the object it decorates

All decorators implement the same interface

A decorator is instantiated with a reference to the object it decorates

Once all decorators have been created it is very hard to add a new one

Ans:-

All decorators implement the same interface

A decorator is instantiated with a reference to the object it decorates

Question: You programmatically apply a filter using openpyxl, but when you save and open the workbook, the filter has not taken effect. Why?

Filters will only work within Python, not in Excel

The filter data API is currently somewhat buggy, and you need to hit the “Reapply” button in Excel

Filters will only work within Excel, not in Python

You need to use Pandas rather than openpyxl to apply the filter

Ans:- The filter data API is currently somewhat buggy, and you need to hit the “Reapply” button in Excel

Question: What is the bind method of a socket instance used for?

To bind a socket to another application at the other end of the socket

To bind a socket to a randomly chosen address

To bind a socket to the specified address

To bind a prevent any further activity on the socket

Ans:- To bind a socket to the specified address

Question: What is the type of data structure that we can use for the body of a POST request when making a call to requests.post()?

dictionary

list

A list of strings

A file

Ans:- dictionary

Question: A pandas data frame contains rows that are uniquely identified using a combination of country and year. Which of the following statements about this data frame is accurate?

The dataframe has a primary key with two key attributes

The dataframe is a pivot table in openpyxl

The dataframe is mal-formed and will not be valid in Pandas

This dataframe has a multi-level index

Ans:- This dataframe has a multi-level index

Question: Which of the following is true of the Adapter pattern?

Uses a consistent interface across all components

This pattern cannot be implemented in Python as it is not very useful

Code for legacy components needs a complete rewrite

Newer components need a rewrite to match legacy interfaces

Ans:- Uses a consistent interface across all components

Question: What is the objective of the flyweight design pattern?

Easy communication between multiple resources

More efficient creation of large number of resources

Easy access to the right resource based on use case

Sharing resources among a large number of lightweight objects

Ans:- Sharing resources among a large number of lightweight objects

Question: Under what conditions might you choose to implement the Adapter design pattern?

When you want to present a consistent interface to your clients whether they use new or old compoenents

When you want to separate how objects are created from how they are represented

When you want to avoid rewriting your legacy components

When you want to refactor the code in your legacy components

Ans:-

When you want to present a consistent interface to your clients whether they use new or old compoenents

When you want to avoid rewriting your legacy components

Question: An excel workbook contains the formula “=A2 * B$2” in cell location C2. This formula is copied to cell D4. What formula will be contained in cell D4?

“=A2 * B$2”

“=B4 * C$4”

“=B4 * C$2”

“=$B$2 * B$2”

Ans:- “=B4 * C$2”

Question: Which of the following techniques would we use to insert up and down arrows for a column containing sales performance data ?

Custom style

Color scale rule

Icon set rule with arrows

Differential style with a formula-based rule

Ans:- Custom style

Question: Which of these methods in the pickle module can be used to de-serialize an object?

dumps(<object>)

serialize(<object>)

loads(<object>)

tobytes(<object>)

Ans:- loads(<object>)

Question: What occurs when the timeout value set for a socket has been exceeded?

The application raises an exception

The application logs a warning

The application using the socket freezes

The application using the socket ignores the event

Ans:- The application raises an exception

Question: Which of the following Excel charts is the most suitable for visualizing trends over time?

Bar chart

Bubble chart

Line chart

Scatter plot

Ans:- Line chart

Question: Which of the following libraries will we need to import to work with line charts in Python?

Reference

openpyxl

LineChart

AreaChart

Ans:- openpyxl

Question: The x-axis in a chart represents months. How can we specify that we would only like the first month of each year to be shown on the horizontal chart axis?

chart.x_axis.tickLblSkip = 12

chart.x_axis = dates

chart.x_axis[“January”] = True

chart.x_axis.tickLblSkip = 24

Ans:- chart.x_axis.tickLblSkip = 12

Question: Which of these methods in the pickle module can be used to serialize an object?

dumps(<object>)

loads(<object>)

tobytes(<object>)

serialiaze(<object>)

Ans:- dumps(<object>)

Question: Which of the following best defines a class?

A piece of reusable code which can be invoked over and over again

A global function which is accessible to all objects

A logical unit encompassing state and behavior

A local definition which specifies common characteristics

Ans:- A logical unit encompassing state and behavior

Question: Why can classes be considered analogous to blueprints?

Specifies charactistics of all objects or instances which are built using that blueprint

Is a template which defines how entities which follow that template look and behave

Can only be drawn up by an expert programmer

Once defined, a class cannot be changed like a blueprint

Ans:-

Specifies charactistics of all objects or instances which are built using that blueprint

Is a template which defines how entities which follow that template look and behave

Question: Which of the following statement(s) is/are true?

Objects of a class exist independent of other objects of the same class

Instantiating a class means creating an object of a class

There can be exactly one object created from a class

Objects and instances are subtly different in their implementations

Ans:-

Objects of a class exist independent of other objects of the same class

Instantiating a class means creating an object of a class

Question: Which of these modules in the Python requests package includes definitions of the errors which can be thrown by its HTTP requests?

errors

request_errors

exceptions

http_errors

Ans:- exceptions

Question: What function of the socket module can be used to get the host name of the machine where the program is running?

gethostbyname()

gethostname()

gethost()

hostname()

Ans:- gethostname()

Question: What kind of relationship is inheritance used to model?

Is-like-a relationship

Has-a relationship

Is-a relationship

Contains-a relationship

Ans:- Is-a relationship

Question: Which of the following is considered to be an advantage of object-oriented programming?

Intuitive to write

Promotes code reuse

Data encapsulation

Modular structure for code

Models real-world entities

Ans:-

Promotes code reuse

Data encapsulation

Modular structure for code

Models real-world entities

Question: What is the main point of distinction between a PUT and POST request?

A PUT is idempotent

A PUT request does not include a body

The response to a PUT request does not include a body

A PUT is meant to delete a resource

Ans:- A PUT is idempotent

Consider a class Employee defined as follows:

class Employee:
pass

How would you instantiate an object of the class Employee?

e = create Employee()

e = Employee.create()

e = Employee()

e = new Employee()

Ans:- e = Employee()

Consider the following code below and specify what the output will be of the final print statement.

Class Employee:
    pass

e1 = Employee()
e2 = Employee()

e1.name = “Ram”
print(e2.name)

“Ram”

Empty string

AttributeError

“John”

Ans:- AttributeError

Question: Which TWO of the following objects are returned when invoking a socket object’s accept function?

A socket object which can be used to send and receive data

The address of the host at the other end of the socket

A string containing the name of the connecting host

A stream of bytes containing the name of the connecting host

Ans:-

A socket object which can be used to send and receive data

The address of the host at the other end of the socket

When is the init() special on a class invoked?

When the class template is defined

When the class is first created

When the class is deleted

When other methods are invoked on the class

Ans:-When the class is first created

The “self” input argument is always the first argument in the init() special method. What does it represent?

A utility object to access details external to the class

A reference to the name of the class

A reference to the current instance of a class

A reference to the class

Ans:- A reference to the current instance of a class

Consider the follow bit of code:

class Employee:
def init(self, name):
self.name = name
def get_name(self):
return name
e = Employee(“James”)

Which ways to invoke the get_name() function on object “e” are correct?

e.get_name(e)

e.get_name()

Employee.get_name()

Employee.get_name(e)

Ans:-

e.get_name()

Employee.get_name(e)

Question: Which of these libraries can be used to load RSS feeds into a Python application?

pandas

matplotlib

SQLAlchemy

feedparser

Ans:- feedparser

Question: Which of the following way(s) to define the Employee class is correct?

class Employee(base): pass

class Employee[]: pass

class Employee(object): pass

class Employee: pass

class Employee(): pass

Ans:-

class Employee(object): pass

class Employee: pass

class Employee(): pass

Question: What kind of relationship does class inheritance help model?

Is-a

Has-a

With-a

Like-a

Ans:- Is-a

Question: Which of the following statements is true about classes and inheritance?

The child class is also called the base class

The child class is also called the subclass

The parent class is also called the base class

The parent class is also called the derived class

Ans:-

The child class is also called the subclass

The parent class is also called the base class

Question: Which of the following statements are true about inheritance?

Derived classes can call the init() methods of the base class

Base classes can call the init() method of the derived class

Base classes may provide default method implementations which derived classes override

Question: You have a TCP socket instance called sock. Which of these function calls can be used to receive 20KB of data from the other end of the socket connection?

sock.get(20480)

sock.receive(20)

sock.recv(20480)

sock.get(20)

Ans:- sock.recv(20480)

Question: Using the Response object returned by a GET request call, what property can you use to get the response body?

history

text

headers

config

Ans:- text

Question: Which of the following ways are valid for invoking the superclass init(self, name) method from a derived class? Assume that the base class is named Employee.

Employee().init(self, name)

super().init(self, name)

Superclass.init(self, name)

Employee.init(self, name)

Ans:-

super().init(self, name)

Employee.init(self, name)

Question: What kind of relationships does multiple inheritance help model?

Multiple is-a relationships

Multiple has-a relationships

One like-a and one has-a relationship

One is-a and one has-a relationship

Ans:- Multiple is-a relationships

Question: Which TWO of the following statements about POST requests are TRUE?

All the data submitted in a POST request are included in the URL

The submitted data is included in the request body

They are meant for submitting data to a server

They are meant to request a server for data

Ans:-

The submitted data is included in the request body

They are meant for submitting data to a server

Question: Which TWO of these are valid ways to set a Python TCP socket (represented by the variable sock) to use blocking mode?

Call sock.nonblocking()

sock.blocking(‘non-blocking’)

sock.setblocking(True)

Initialize the TCP socket. It will use blocking mode by default

Ans:-

sock.setblocking(True)

Initialize the TCP socket. It will use blocking mode by default

Question: Match the special functions with the correct arithmetic operation

Answer Options:
A:init()
B:str()
C:add()
D:pow()
E:mul()

Adding objects

A

B

C

D

E
Ans:- C

Raising to a power

A

B

C

D

E
Ans:-D

String representation of object

A

B

C

D

E
Ans:- B

Multiplying objects

A

B

C

D

E
Ans:-E

Initialization of object

A

B

C

D

E
Ans:- A

Question: Which of the following are the functions that you pass in to create a property on a class?

destroyer

updater

setter

deleter

getter

aNS:-

setter

deleter

getter

Question: If you want the built-in len() function to work with your custom class objects what special method would you implement?

__sizeof__()

__length__()

__len__()

__size__()

Ans:- __len__()

Question: When a base class inherits from ABC and when methods with no implementations are tagged with @abstractmethod, how does that help us work with base and derived classes?

Allows multiple inheritance using 10+ base classes

Better code readability and maintainability

Does not allow instantiation of classes where methods have no implementations

Enables multilevel inheritance

Ans:- Does not allow instantiation of classes where methods have no implementations

Question: Consider an object of the class Employee stored in the variable e. When you invoke the print(e) function, what does Python do under the hood?

Invoke the str() method on the Employee object

Invoke the repr() method and if that is not present, invoke the str() method

Invoke the repr() method on the Employee object

Invoke the str() method and if that is not present, invoke the repr() method

Ans:- Invoke the __str__() method and if that is not present, invoke the __repr__() method

Question: What socket types do we specify when initializing a UDP socket?

SOCK_DATA

SOCK_TCP

SOCK_DGRAM

SOCK_STREAM

Ans:- SOCK_DGRAM

Question: Which of the following is true about static methods in Python?

Are bound to the class as well as objects of a class

Has no reference to the state of the class

Are bound to the class and not objects of a class

The first argument is a reference to the class

Ans:- Has no reference to the state of the class

Consider this class as defined below:

class BankAccount:

def __init__(self, balance): 
    self.__amount = balance                          

def __mul__(self, other):
    if type(other) == int:
        return self.__amount * other
    else: 
        raise ValueError('Can only multiply by int')

ba = BankAccount(1000)

What will be the result of this operation below?

ba * 4

Empty result

Error the multiplication is not possible

4000

ValueError: Can only multiply by int

Ans:- 4000

Question: Which TWO of the following statements about HEAD requests are TRUE?

The server response does not contain data in the message body

The header data must be identical to a GET request with the same URL and parameters

The header data will include only whether the requested resource exists

The server response includes a truncated message body

Ans:-

The server response does not contain data in the message body

The header data must be identical to a GET request with the same URL and parameters

If you want your objects to support the + operator, what special method do you need to implement in the object’s class?

__add__()

__plus__()

__total__()

__sum__()

Ans:- __add__()

Question: Which socket types do we specify when initializing a TCP socket?

SOCK_DATA

SOCK_DGRAM

SOCK_TCP

SOCK_STREAM

Ans:- SOCK_STREAM

Question: Which of these function calls will return a file object pointing to a file opened in read-only mode in the binary format?

open(‘’, ‘r+’)

open(‘’, ‘rb’)

fileopen(‘’, ‘read’, ‘binary’)

fileopen(‘’, ‘r’, ‘b’)

Ans:- open(‘<file_path>’, ‘rb’)

If you want to decorate a property called “salary” as a setter what decorator would you use?

@property.setter

@property

@salary.setter

@setter.salary

Ans:- @salary.setter

Which of the following is true about class methods in Python?

The first argument is a reference to the class

Has no reference to the state of the class

Are bound to the class and not objects of a class

Are bound to the class as well as objects of a class

Ans:-

The first argument is a reference to the class

Are bound to the class and not objects of a class

In order to have your custom class objects support iteration using for-loops which of the following two special methods do you need to implement?

__prev__()

__len__()

__iter__()

__next__()

Ans:-

__iter__()

__next__()

Question: What is returned when we invoke a socket object’s send() function?

A number representing the number of bytes sent on the socket

A boolean value representing a success or failure of the send

A string representation of the data sent on the socket

A byte stream representing the data sent on the socket

Ans:- A number representing the number of bytes sent on the socket

Question: Which of these fields in an HTTP request header helps identify the type of application making the request?

Requesting-App

User-Agent

User-Type

Application-Type

Ans:- User-Agent

Question: Identify the elements that are configured in Robot files for test automation.

Framework selection

Resource

Test case

Execution steps

Ans:-

Resource

Test case

Question: Recall some of the essential features provided by the Behave BDD framework.

Helps coordinate Dev and QA teams

Facilitates modular testing with one fixture from another

Can execute BDD testing without any complications

Facilitates better product specs

Ans:-

Can execute BDD testing without any complications

Facilitates better product specs

Question: Which arguments can we pass to @pytest.mark.parameterize to simplify testing Python code?

value

framework

testdata

ids

Ans:-

testdata

ids

Question: What is a potential risk when sending large amounts of data over TCP sockets in non-blocking mode?

The sending application may terminate unexpectedly

The sending application may wait indefinitely for the transfer to take place

All the data may not be transferred if the socket’s write buffer gets full

The receiving application may terminate unexpectedly

Ans:- All the data may not be transferred if the socket’s write buffer gets full

Question: Which test cases are a good candidate for test automation?

Repeatedly executed test cases

Test cases that can be manually executed easily

Simple function test cases

Time-consuming test cases

Ans:-

Repeatedly executed test cases

Time-consuming test cases

Question: Which elements can we write to define services and prepare them for testing using Flask?

@app.route(“/”)

app=Flask(name)

app.module(“/get”)

add.testRoute(“/”)

Ans:-

@app.route(“/”)

app=Flask(name)

Question: What type of data structure is the history property of a Response object?

A list of Response objects

A JSON array

A list of HTTP status codes

A comma-separated string of HTTP status codes

Ans:- A list of Response objects

Question: Select the primary paradigm for the Python programming language.

Functional

Multi-paradigm

Object oriented

Scripting

Ans:-Multi-paradigm

Question: Specify the essential characteristics of the Nose testing framework.

Nose is well documented

Nose is not nearly as well documented as Pytest

Nose is highly suitable for automating complex tests

Can find and execute test files automatically

Ans:-

Nose is not nearly as well documented as Pytest

Can find and execute test files automatically

Question: Which statements can we use to configure Selenium WebDriver in Python scripts?

driver.test()

driver.implicitly_wait(30)

driver.invokeTest()

webdriver.Firefox()

Ans:-

driver.implicitly_wait(30)

webdriver.Firefox()

Select the reason why the code provided is not valid in Python 3.

print ‘Hello, {}’.format(recipient)

Missing semi-colon at the end of the statement

Missing parentheses

Strings require double quotes

The format method is not available

Ans:- Missing parentheses

Question: Which two of the following statements are valid descriptions of Jupyter notebooks?

It is an interactive IDE

It is a web application

It does not support Python

It is a desktop application

Ans:-

It is an interactive IDE

It is a web application

Question: Identify the different approaches of installing Behave in development environments using Python.

Installing using GitHub distribution

Installing using source distribution

Installing using Behave configuration file

Installing using EXE commands

Ans:-

Installing using GitHub distribution

Installing using source distribution

Question: Recall the keywords that we can use to define features in Behave framework files.

Catch

Scenario

Else

Feature

Ans:-

Scenario

Feature

Question: Recall the elements that we need to specify in Postman to test APIs that were built using Flask.

Request method

API URL

Data provider connection

Importing Python codes

Ans:-

Request method

API URL

What data type is defined in the following Python statement?

A = (1, 2, 3)

dictionary

tuple

list

array

Ans:- tuple

What syntax is used to import objects from within modules?

include

using namespace

from … import

import … using

Ans:- from … import

Question: What are the advantages of using Anaconda for AI?

Ability to install packages in specific environments as needed

Ability to maintain separate working environments

Anaconda will check your code for bugs

Create a visualized version of your code

Brings many tools for data science & machine learning in just one install

Ans:-

Ability to install packages in specific environments as needed

Ability to maintain separate working environments

Brings many tools for data science & machine learning in just one install

Question: Match the specifics of using particular IDEs.

Answer Options:
A:Easy code navigation & debugging with specific Python support
B:Cross platform IDE with package manager & auto completion
C:Lightweight & fast data analysis IDE
D:Large pool of languages & integration plugins available

Eclipse

A

B

C

D
Ans:- B

Spyder

A

B

C

D
Ans:- C

PyCharm

A

B

C

D
Ans:- A

Atom

A

B

C

D
Ans:- D

Question: Why do so many companies use Python when developing AI?

It is hard to start developing with Python

It has large community support

It is easy to learn for many people

Need to write less code by reusing existing implementations

It is more robust and provides more efficiency

Ans:-

It has large community support

It is easy to learn for many people

Need to write less code by reusing existing implementations

Question: What two of the following statements about making GET requests using the Python requests package are TRUE?

The URL in the request can be different than the one in the request

The URL in the response is always the same as the one used in the request

A GET request call can include parameters along with a URL

GET requests don’t support parameters

Ans:-

The URL in the request can be different than the one in the request

A GET request call can include parameters along with a URL

Question: What status code is expected when successful content is return from a URL request in Python?

300

200

400

500

Ans:- 200

Question: What makes Python unbeatable for AI development for the next few years?

It provides high level of security and vast amount of debugging tools

Easy to read code allows to learn faster

Large amount of open source community support & vast amount of libraries

It supports rapid development and fast deployment

It has high-speed computation capabilities

It has very low runtime

Ans:-

Easy to read code allows to learn faster

Large amount of open source community support & vast amount of libraries

It supports rapid development and fast deployment

Question: Match the Python libraries with their purposes.

Answer Options:
A:Popular library to develop and run ML/DL models on CPU, GPU, & TPU
B:Model management and testing functionality
C:Most used libraries for data collection, pre-processign, & data manipulation
D:Provide useful wrappers for building machine learning models & algorithms
E:Advanced AI library for ML/DL with high graphic capabilities

PyTorch

A

B

C

D

E
Ans:- E

Metaflow & Airflow

A

B

C

D

E
Ans:- B

Scikit-learn & Scipy

A

B

C

D

E
Ans:- A

NumPy & Pandas

A

B

C

D

E
Ans:- D

Question: Match popular AI tools with their functions.

Answer Options:
A:TF Serving, Azure Kubernetes Services
B:TensorFlow, Keras, Meta Flow, & ML Flow
C:Spark & Hadoop, R and Python pandas package
D:Tableau, Plotly, & Matplotlib

Model building & model management

A

B

C

D
Ans:- B
Model production

A

B

C

D
Ans:- A

Data gathering & data pre-processing

A

B

C

D
Ans:- C

Visualization

A

B

C

D
Ans:- D

Question: What keyword is used to define a Python function?

func

def

defun

fn

Ans:- def

Question: Which of these attributes of an HTTP Response object contains the response in the form of bytes?

content

text

response_bytes

data

Ans:- content

Question: What keyword is used for the else if clause of a Python conditional statement?

while

elif

fi

elseif

Ans:- elif

Question: Match the corporations with their contributions to Python open source community.

Answer Options:
A:CNTK – a single platform to support multiple AI directions
B:MXNet – large AI framework that supports AWS
C:CreateML – framework for deployment of machine learning models
D:TensorFlow – one of the leading libraries for implementing neural network
E:PyTorch – extensive mathematical library for AI

Amazon

A

B

C

D

E
Ans:- B

Google

A

B

C

D

E
Ans:- D

Facebook

A

B

C

D

E
Ans:- E

Microsoft

A

B

C

D

E
Ans:- A

Question: What does the ‘a’ file mode do when opening a file?

Opens the file in binary mode

Opens the file for writing and overwrites the file

Opens the file for reading

Opens the file for appending to the end of the file

Ans:- Opens the file for appending to the end of the file

Question: Which of the following are ways to extend a class?

Inheritance

Delegation

Encapsulation

Composition

Abstraction

Ans:-

Inheritance

Delegation

Composition

Question: Which of the following correctly defines the principle of single responsibility?

A class or component should not contain too many interfaces

A class or component should talk to other components using events

A class or component should do only one thing and do it well

A class or component should implement interfaces that are granular

Ans:- A class or component should do only one thing and do it well

Question: If you don’t follow Liskov’s Substitution principle of good design what might be the experience of users using your code?

They will not be able to rely on the contract established by the base class

Different derived classes will have different and unexpected behaviors

Too many APIs will be exposed by a single class

Code will be poorly structured

Ans:-

They will not be able to rely on the contract established by the base class

Different derived classes will have different and unexpected behaviors

Question: Which is the best definition of the Hollywood principle of good design?

A higher level module should communicate with the lower level module if it wants to

Both higher and lower level modules should be in constant communication

A lower level module should query the higher level module as it needs to

A higher and lower level module should never talk to each other

Ans:- A higher level module should communicate with the lower level module if it wants to

Question: Using the Response object returned by a GET request call, what property can you use to check that the HTTP request was successfull?

headers

success

get_status

status_code

Ans:-status_code

Question: Given a loop created using while True:, how is the loop terminated?

quit

break

continue

exit

Ans:- break

Question: If your code does not follow the Interface Segregation principle of good design, what might be the experience of users using your class?

Interfaces will be bloated as each interface tries to do too much

Clients will be forced to implement interfaces they do not need

Higher level modules will invoke lower level modules

Each component will have too much knowledge of another component

Ans:-

Interfaces will be bloated as each interface tries to do too much

Clients will be forced to implement interfaces they do not need

Question: If your code does not follow the Dependency Inversion principle of good design, what might be the experience of users using your class?

Each component will have too much knowledge of another component

Each class will try to implement too many behaviors

Higher level modules will invoke lower level modules

Clients will be forced to implement interfaces they do not need

Ans:- Higher level modules will invoke lower level modules

Question: Which is a difference between structural and behavioral design patterns?

Structural patterns depend heavily on object creation, behavioral patterns are independent of object creation

Structural patterns focus on interaction between internal components, behavioral patterns focus on interaction with the external world

Behavioral patterns focus on interaction between internal components, structural patterns focus on interaction with the external world

Behavioral patterns don’t allow internal components to communicate, structural patterns allow all kinds of communication

Ans:- Structural patterns focus on interaction between internal components, behavioral patterns focus on interaction with the external world

Question: Which of these header fields in a Response object can be used to check whether the response content is in JSON format?

is_json

Data-Format

Response-Format

Content-Type

Ans:-Content-Type

Question: How is a cell uniquely identified in Excel?

With a primary key

Using multi-level indexing

By specifying its row and column

Via a single-level index

Ans:- By specifying its row and column

Question: Which are types or categories of design patterns?

Architectural

Notional

Creational

Behavioral

Structural

Ans:-

Creational

Behavioral

Structural

Question: You are designing the class structure for students in a school. You need to store personal details of a student, courses in which they are enrolled and save all this to a database.
You want your classes to follow the Single Responsibility principle. In which of the following designs is this achieved?

A separate class for personal details of a student, a separate class for course details of a student and a third class for database operations

A single Student class should be able to store information as well as write all details out to a database

A separate class to hold personal details of a student along with database operations and another class to hold course details along with database operations

Separate class for Students which holds personal details as well as course details, separate class for database operations

Ans:- A separate class for personal details of a student, a separate class for course details of a student and a third class for database operations

Question: A new workbook is created using openpyxl. What operation must be performed before it can be opened using Microsoft Excel?

The file must be converted to CSV or tab-delimited format and saved to disk

The workbook must be converted to JSON and written to disk

The file must be shared with Microsoft Excel

The in-memory workbook must be written to disk using workbook.save

Ans:- The in-memory workbook must be written to disk using workbook.save

Question: Which is a correct explanation of the global object pattern in Python?

Set up a single instance of a class by keeping the class private to a module, initializing it once and then exposing it via a global variable

Exposing private classes as global variable which can then be used to spin up multiple instances of the same class

Exposing a public class as a global variable which can create multiple objects of the public class

Exposing global objects as public classes which are accessible within modules that can be imported

Ans:- Set up a single instance of a class by keeping the class private to a module, initializing it once and then exposing it via a global variable

Question: Why might the Builder pattern be less useful when working with Python?

Python objects take in only a limited number of input arguments

The use of default values for arguments make objects easy to create

Python supports the Builder pattern as a part of a built-in package

Builders cannot be implemented in Python

Ans:- The use of default values for arguments make objects easy to create

Question: Under what conditions might you choose to implement the Singleton design pattern?

You want to lazily instantiate an object only when needed

The object is ephemeral

The object is a global object with no clear owner

The object will be used only once

You want only one object of a class to be in existence

Ans:-

You want to lazily instantiate an object only when needed

The object is a global object with no clear owner

You want only one object of a class to be in existence