wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

variables , if … else, while and loop for_HKICO_Python

Total questions: 27

Worksheet time: 14mins

Name
Class
Date
1.

What is the output of the following code?

a)

A. JamesJamesJamesJamesJamesJames

b)

B. JamesJamesJamesJamesJames

c)

C. JamesJamesJamesJames

d)

D. JamesJamesJames

e)

E. Error: invalid syntax

2.
a)

A. 20

b)

B. 21

c)

C. 10

d)

D. 30

e)

E. None of the above

3.
a)

b)

c)

d)

e)

E. It doesn’t generate any output.

4.

What gets printed?

a)

A. 4

b)

B. 3

c)

C. 2

d)

D. 1

e)

E. 7

5.
a)

A. 2, 4, 6

b)

B. 0, 1, 2, 4, 5, 6

c)

C. 0, 1, 4, 5

d)

D. 0, 1, 4, 5, 6, 7, 8, 9

e)

E. 1, 2, 4, 5, 6

6.

Consider the following code,
What is the output?

a)

A. 1

b)

B. 2

c)

C. 3

d)

D. 4

e)

E. 5

7.

What gets printed as the output of the below code?

a)

A. 1

b)

B. 2

c)

C. 3

d)

D. 4

e)

E. None of the above

8.

Consider the following code,
What is the output?

a)

A. 7

b)

B. 6

c)

C. 4

d)

D. 2

e)

E. 1

9.


a)

A. The recursive function never terminates

b)

B. -1

c)

C. 5

d)

D. 0

e)

E. None of the above

10.

What is the expected output of the program?

a)

A. None

b)

B. a

c)

C. C

d)

D. 2

e)

E. None of the above

11.

Which one will display when this code is run?

a)

b)

c)

d)

e)

E. None of the above

12.

What is the Output of the following code?

a)

A. [0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5]

b)

B. [0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5]

c)

C. [0.5, 1, 1.5, 2]

d)

D. [0.5, 1, 5.5]

e)

E. The Program executed with errors

13.

Please select the correct expression to reassign a global variable “x” to 20 inside a function fun1()

a)

A. global x =20

b)

B. global var x

x = 20

c)

C. global.x = 20

d)

D. global x

x = 20

e)

E. None of the above

14.

What is the output of the following variable assignment?

a)

A. Error


b)

B. 76


c)

C. 1


d)

D.75


e)

E. None


15.

What is the output of the following nested loop?

a)

b)

c)

d)

e)

16.

Given the nested if-else structure below, what will be the value of x after code execution completes

a)

A. 2


b)

B. 0


c)

C. 3


d)

D. 4


e)

E. 1


17.

Which is the better statement if x+=1 is removed?

a)

A. There is no difference

b)

B. The loop is infinite

c)

C. The print function is stopped

d)

D. The output equals to 10

e)

E. None of the above

18.

What is the expected output of the following code?

a)

A. 4

b)

B. 5

c)

C. 6

d)

D. 7

e)

E. None of the above

19.

What is the output?

a)

A. 154 6 25

b)

B. 155 6 24

c)

C. 154 5 24

d)

D. 155 5 25

e)

E. None of the above

20.
a)

A. [A , F]

b)

B. [‘A’ , ‘F’]

c)

C. [B , E]

d)

D. [‘B’ , ‘E’]

e)

E. None of the above

21.

Given the code:
Which of the following is code correct if the output is I ?

a)

A. print(x[3])

b)

B. print(x[4])

c)

C. print(var[2])

d)

D. print(var[3])

e)

E. None of the above

22.

Given the code:
Which of the following statement is/are correct?

a)

A. split() is to split a string into a list

b)

B. [word] = line

c)

C. The output is ordered by ascending order

d)

D. All the above are correct

e)

E. None of the above

23.

Which of the following is not a Python built-in types?

a)

A. int

b)

B. double

c)

C. complex

d)

D. list

e)

E. All of the above

24.
a)

A. 61

b)

B. 42

c)

C. 13

d)

D. 11

e)

E. None of the above

25.
a)

A. 0

b)

B. 10

c)

C. 170

d)

D. 495

e)

E. None of the above

26.
a)

A. 0

b)

B. 10

c)

C. 170

d)

D. 495

e)

E. None of the above

27.
a)

A. True

b)

B. False, list a is consumed but b is not, because list a is not explicit

c)

C. False, every instance of list does not equal (evaluate to True) in case of ‘==’ operator

d)

D. False, values of elements are not equal in list a and b, they appear to be the same when printed out

e)

E. None of the above