wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Season 4 #Spaic Python Weekly Quiz

Total questions: 20

Worksheet time: 11mins

Name
Class
Date
1.

How are lambda functions useful? Select all that apply:

a)

Lambda functions make it easy to read the code.

b)

They are useful in allowing quick calculations or processing as the input to other functions.

c)

They can be useful as quick, throwaway single-line functions.

d)

Lambda functions are used for functional programming.

2.

What are the common functional programming methods that use lambdas? Select all that apply​:

a)

reduce()

b)

filter()

c)

map()

d)

lookup()

3.

What would be the output of the following code snippet?

(lambda x: (x + 3) * 5 / 2)(3)

a)

0

b)

SyntaxError

c)

30.0

d)

15.0

4.

Which of the following are true for objects of Python’s set type:

a)

The order of elements in a set is significant.

b)

A set may contain elements that are mutable.

c)

A given element can’t appear in a set more than once.

d)

Sets are mutable.

5.

What is the result of this statement:

a)

{'q', 'r', 'x', 'u', 'b', 'a'}

b)

{}

c)

set()

d)

{'b', 'r', 'a'}

6.

What is the output from this print() function call:

a)

3 1 2

b)

3 2 1

c)

3 1 1

d)

3 1 0

7.

What are the modules that must be imported when using scikit-Learn for Linear regression :

a)

from sklearn.model_selection import train_test_split

b)

from sklearn.linear_model import LinearRegression

c)

from sklearn import metrics

d)

from sklearn import preprocessing

e)

All the above

8.

X = data[['TV', 'Radio', 'Newspaper']]

y = data['Sales']

How can we split the data into training and testing sets :

a)

X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=1)

b)

train_test_split(X, y, random_state=1)

c)

X_train, y_train= train_test_split(X, y, random_state=1)

d)

None of the above

9.

To train the data in LinearRegression :

# instantiate

linreg = LinearRegression()


# fit the model to the training data (learn the coefficients)

linreg.fit(X_train, y_train)

a)

True

b)

False

10.

To print the intercept and coefficients after the training of Linear regression : print(linreg.intercept) , print(linreg.coef)

a)

True

b)

False

11.

To calculate the metrics for linear regression in scikit-learn :

a)

# calculate Mean Absolute Error

print(metrics.mean_absolute_error(true, pred))

b)

# calculate Mean Squared Error

print(metrics.mean_squared_error(true, pred))

c)

# calculate Root Mean Squared Error

print(np.sqrt(metrics.mean_squared_error

(true, pred)))

d)

All the above

12.

If a=[1,2,3,4,5] what will be the result of following code?

print(a[1::-1])

a)

[5,4]

b)

[2,1]

c)

[3, 2]

d)

[4]

13.

Is the following Python code valid?

a)

Yes, [1,2,3] is printed

b)

No, invalid syntax

c)

Yes, (1,2,3) is printed

d)

1 is printed

14.

What will be the output of the following Python code?

>>>"Welcome to Python".split()

a)

[“Welcome”, “to”, “Python”]

b)

(“Welcome”, “to”, “Python”)

c)

{“Welcome”, “to”, “Python”}

d)

“Welcome”, “to”, “Python”

15.

Suppose list1 is [1, 3, 2], What is list1 * 2?

a)

[2, 6, 4]

b)

[1, 3, 2, 1, 3]

c)

[1, 3, 2, 1, 3, 2]

d)

[1, 3, 2, 3, 2, 1]

16.

Say s=”hello” what will be the return value of type(s)?

a)

int

b)

bool

c)

str

d)

String

17.

What will be the output of the following Python statement?

>>>"abcd"[2:]

a)

a

b)

ab

c)

cd

d)

dc

18.

What will be the output of the following Python code?

a)

{1: 5}

b)

{1: 5, 2: 3}

c)

Error, syntax error for pop() method

d)

{1: 5, 3: 4}

19.

Read the following Python code carefully and point out the global variables?

a)

x

b)

y and z

c)

x, y and z

d)

Neither x, nor y, nor z

20.

Is the following Python code correct?

a)

True

b)

False