wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

In a Python program, a control structure:

a)

Defines program-specific data structures

b)

Directs the order of execution of the statements in the program

c)

Manages the input and output of control characters

d)

Dictates what happens before the program starts and after it terminates

2.

Syntax error in python is detected by _________at _______

a)

interpreter/ run time

b)

compiler/ compile time

c)

compiler/ run time

d)

interpreter/ compile time

3.

Which one of the following if statements will not execute successfully:

a)

if (1, 2):


print('foo')

b)

if (1, 2):

print('foo')

c)

if (1, 2):

print('foo')

d)

if (1, 2): print('foo')

e)

if (1, 2):

print('foo')

4.

Which among them will produce {'a', 'b', 'c'}?

a)

Tuple(''abc'')

b)

Set(''abac'')

c)

List(''abc'')

d)

None of the above.

5.

Which among them is incorrect for set s={100,101,102,103}

a)

Max(s)

b)

Sum(s)

c)

Len(s)

d)

Print(s[3])

6.

What signifies the end of a statement block or suite in Python?

a)

A comment

b)

end

c)

A line that is indented less than the previous line

d)

}

7.

What is the output for −

S = [['him', 'sell'], [90, 28, 43]]

S[0][1][1]

a)

'e'

b)

'i'

c)

'90'

d)

'h'

8.

The following if/elif/else statement will raise a KeyError exception:


d = {'a': 0, 'b': 1, 'c': 0}

2

3if d['a'] > 0:

4 print('ok')

5elif d['b'] > 0:

6 print('ok')

7elif d['c'] > 0:

8 print('ok')

9elif d['d'] > 0:

10 print('ok')

11else:

12 print('not ok')

a)

TRUE

b)

FALSE

9.

What is the output of the following

l = [None] * 10

print(len(l))

a)

10

b)

0

c)

Syntax Error

10.

Select all the correct options to copy a list


aList = ['a', 'b', 'c', 'd']

a)

newList = copy(aList)

b)

newList = aList.copy()

c)

newList.copy(aList)

d)

newList = list(aList)