wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

TIU Quiz-9

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

What will be the output of the following code?

a)

10

b)

5

c)

lambda x: x * 2

d)

Error

2.

Which of the following is a correct implementation of list comprehension to create a list of squares of numbers from 1 to 5?

a)

[x ** 2 for x in range(1, 6)]

b)

{x ** 2 for x in range(1, 6)}

c)

{x: x ** 2 for x in range(1, 6)}

d)

[x ** 2 in range(1, 6)]

3.

Which of the following is the correct way to sort a list of tuples based on the second element of each tuple in descending order?

a)

sorted(tuples, key=lambda x: x[1], reverse=True)

b)

sorted(tuples, key=lambda x: x[0], reverse=True)

c)

sorted(tuples, key=lambda x: x[1], reverse=False)

d)

sorted(tuples, key=lambda x: x[0], reverse=False)

4.

What is the output of the following code snippet?

a)

2024 5 16

b)

16 5 2024

c)

5 16 2024

d)

Compile Time Error

5.

How can you convert a datetime object into a formatted string representation of the date and time?

a)

str(date_obj)

b)

date_obj.strftime("%Y-%m-%d %H:%M:%S")

c)

date_obj.format("%Y-%m-%d %H:%M:%S")

d)

format(date_obj, "%Y-%m-%d %H:%M:%S")

6.

What does the map() function in Python do?

a)

Applies a function to each element of an iterable

b)

Creates a map object from an iterable

c)

Merges two iterables into one

d)

Sorts elements of an iterable

7.

What will be the output of the following code?

a)

[25, 10, 8]

b)

[25, 10, 8, 15]

c)

[30, 10, 8]

d)

Error

8.

Given a list numbers = [1, 2, 3, 4, 5], what does [x for x in numbers if x % 2 == 0] return?

a)

[1, 3, 5]

b)

[2, 4]

c)

[1, 2, 3, 4, 5]

d)

[4, 2]

9.

Which of the following is NOT a valid way to define an anonymous (lambda) function in Python?

a)

lambda x: x * 2

b)

def(x): return x * 2

c)

lambda x, y: x + y

d)

lambda : "hello"

10.

What is the result of sum([x for x in range(10) if x % 2 == 0])?

a)

20

b)

25

c)

30

d)

None of These