wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Quiz 2

Total questions: 25

Worksheet time: 13mins

Name
Class
Date
1.
  1. What will be the output of the following Python program?

a)

8

b)

2

c)

1

d)

5

2.

What will be the output of the following Python code snippet?

z=set('abc$def')

'a' in z

a)

Error

b)

No output

c)

True

d)

False

3.

What will be the output of the following Python code?

print("Hello {0[0]} and {0[1]}".format(('foo', 'bin')))
a)

Hello (‘foo’, ‘bin’) and (‘foo’, ‘bin’)

b)

Hello foo and bin

c)

Error

d)

None of the mentioned

4.

Which function is used to read all the characters?

a)

Read()

b)

Readcharacters()

c)

Readall()

d)

readchar()

5.

Which of the following are the modes of both writing and reading in binary format in file?

a)

wb

b)

w

c)

wb+

d)

w+

6.

what does ~~~~~~~5 evaluate to ?

a)

+11

b)

-5

c)

+5

d)

-11

7.

what will be the output of the following code?

x=1234

reg="integers:....%d...%-6d...%06d"%(x,x,x)

print(reg)

a)

error

b)
integers:....1234...1234  ...123400
c)
integers:....1234...1234  ...001234
d)
integers:....1234...1234...1234
8.

What will be the output of the following code?

a)

good

b)

false

c)

bad

d)

hello

9.

what will be the output of the following code?

a)

-2 -1

b)

error

c)

0

d)

none of the above mentioned

10.

what is the output of the following code?

A=[[1,2,3],

[4,5,6],

[7,8,9]]

A[1]

a)

[1,2,3]

b)

error

c)

[2,5,8]

d)

[4,5,6]

11.

write a list comprehension for number and its cube for:

l=[1,2,3,4,5,6,7,8,9]

a)

[x**3 in l]

b)

[x^3 in l]

c)

[x**3 for x in l]

d)

[x^3 for x in l]

12.

What is the output of the following code?

a)

5 12

b)

12 5

c)

error

d)

20, 5

13.

int(1011)?

a)

13

b)

1011

c)

11

d)

1101

14.

which function is used to find factorial of a number using math module?

a)

fact()

b)

factorial()

c)

math.fact()

d)

none of the above

15.

What will be the output of the following Python code?

x = ['ab', 'cd']
print(len(list(map(list, x))))))
a)

2

b)

4

c)

error

d)

none of the above

16.

Which of the following concepts is not a part of Python?

a)

Pointers

b)

Loops

c)

Dynamic Typing

d)

All the above

17.


What will be the output of the following code snippet?

a)

Global

b)

Local

c)

None

d)

Cannot be predicted

18.

What will be the output of the following code snippet?

example = ["Sunday", "Monday", "Tuesday", "Wednesday"];

print(example[-3:-1])


a)

['Monday', 'Tuesday']

b)

['Sunday', 'Monday']

c)

['Tuesday', 'Wednesday']

d)

['Wednesday', 'Monday']

19.


What will be the type of the variable sorted_numbers in the below code snippet?

numbers = (4, 7, 19, 2, 89, 45, 72, 22)
sorted_numbers = sorted(numbers)
print(sorted_numbers)


a)

List

b)

Bubble sort

c)

Tuple

d)

String

20.

What will be the output of the following code snippet?

dict1 = {'first' : 'sunday', 'second' : 'monday'}

dict2 = {1: 3, 2: 4}

dict1.update(dict2)

print(dict1)

a)

{'first': 'sunday', 'second':'monday', 1: 3, 2: 4}

b)

{1:3, 2:4}

c)

{'first': 'sunday', 'second': 'monday'}

d)

all the above

21.

What will be the output of the following code snippet?

a)

[0,1,4,9,16]

b)

[1,4,9,16,25]

c)

[0,1,2,3,4]

d)

[1,2,3,4,5]

22.

As what datatype are the *args stored, when passed into a function?

a)

List

b)

Tuple

c)

Dictionary

d)

None of the above

23.

What will be the output of the following code snippet?

set1 = {1, 3, 5}

set2 = {2, 4, 6}

print(len(set1 + set2))

a)

3

b)

6

c)

0

d)

error

24.

In which language is Python written?

a)

c++

b)

c

c)

java

d)

None of the above

25.

What will be the output of the following code snippet?

from math import *

a = 2.19 b = 3.999999 c = -3.30

print(int(a), floor(b), ceil(c), fabs(c))

a)

2 3 -3 3.3

b)

3 4 -3 3

c)

2 3 -3 3

d)

2 3 -3.3 3