wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Programming Quiz

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

What is the purpose of the print() function in Python?

a)

To display output to the console

b)

To read user input

c)

To create a variable

d)

To define a function

2.

Is Python sensitive to whitespace when defining code blocks?

a)

Yes

b)

No

c)

Only in functions

d)

Depends on the operating system

3.

Which symbol is used to create a list in Python?

a)

( )

b)

[ ]

c)

{ }

d)

< >

4.

Which of the following is a valid variable name in Python?

a)

1st_variable

b)

my-variable

c)

myVariable

d)

my variable

5.

How do you start a function definition in Python?

a)

function myFunction():

b)

def myFunction():

c)

create myFunction():

d)

myFunction():

6.

What is the output of the following code? x = 5 print(x * 2)

a)

10

b)

5

c)

25

d)

Error

7.

Which of the following statements assigns the value of 10 to the variable x in Python?

a)

x:=10

b)

let x = 10

c)

x = 10

d)

x ← 10

8.

What will be the output of this code? for i in range(3): print(i)

a)

0 1 2

b)

1 2 3

c)

0 1 2 3

d)

0 1 2 3 4

9.

How do you start writing a for loop in Python?

a)

for each i in x:

b)

for i = 1 to x:

c)

for i in x:

d)

for i > x:

10.

What would be the value of ‘new_score’ after running this code:
score = 44
total = 1

new_score = score * 2

a)

88

b)

44

c)

45

d)

22

11.

What is the output of the following code? print("Hello " * 3)

a)

Hello Hello Hello

b)

Hello 3

c)

Hello Hello Hello 3

d)

Error

12.

Which operator is used to check equality in Python?

a)

==

b)

=

c)

===

d)

!=

13.

How do you start writing a for loop that iterates over a list called items?

a)

for item in items:

b)

for each item in items:

c)

for item: items

d)

foreach item in items:

14.

What will be the output of this code? x = [1, 2, 3] print(len(x))

a)

3

b)

2

c)

1

d)

Error

15.

What is the output of the following code?

def calculate (num1, num2):

answer = num1 * num2

print(answer)

calculate(2, 5)

a)

11

b)

7

c)

10

d)

answer

16.

What will the following code output? x = "Hello" print(x[1])

a)

H

b)

e

c)

Hello

d)

Error

17.

Which of these codes is the correct syntax?

a)

Print ("Hello World")

b)

print ("Hello World")

c)

PRINT ("Hello World")

d)

print "Hello World"

18.

Which built in function can be used in Python to return a string in upper case letters?

a)

toUpper()

b)

upperCase()

c)

capitalize()

d)

upper()

19.

What sort of error occurs when the program runs but you do not get the correct answer you expected?

a)

Answer Error

b)

Syntax Error

c)

Run-time Error

d)

Logical Error

20.

what does this code display:
counter = 1

while counter <4:

                print (counter)

counter = counter + 1

a)

1 2 3 4

b)

1 2 3

c)

0 1 2 3

d)

0 1 2 3 4