wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Quiz for Grade 8

Total questions: 24

Worksheet time: 12mins

Name
Class
Date
1.

What will the following code output?
st = "Python"

print(st[2])

a)

P

b)

y

c)

t

d)

h

2.

What does len('Hello World') return?

a)

10

b)

11

c)

12

d)

9

3.

What is the output of
print ("Hello" + " World")?

a)

Hello World

b)

HelloWorld

c)

Error

d)

Hello

4.

How many times will this loop run?
for i in range(3):
print(i)

a)

2

b)

3

c)

4

d)

0

5.

What is the output of:
for i in range(2, 5):

print(i)

a)

2, 3, 4

b)

2, 3, 4, 5

c)

3, 4, 5

d)

None

6.

What does range(5, 10, 2) produce?

a)

5, 6, 7, 8, 9

b)

5, 7, 9

c)

6, 8, 10

d)

5, 10

7.

What is the output of the following function?
def greet():
print('Hello')

greet()

a)

Hello

b)

Error

c)

None

d)

greet

8.

What does this function return?
def add(a, b):
return a + b
print(add(2, 3))

a)

2

b)

3

c)

5

d)

Error

9.

Which is a correct function definition?

a)

def my_function a, b):

b)

def my_function(a, b):

c)

function my_function(a, b):

d)

my_function def(a, b):

10.

What is the output of:
def repeat(word):
return word * 2
print(repeat('Hi'))

a)

HiHi

b)

Hi Hi

c)

Hi2

d)

Error

11.

What will the following code output?
def my_func():
return 'Hi'
print(my_func() + ' there!')

a)

Hi there!

b)

HiThere!

c)

Error

d)

None

12.

What does len('Hello World') return?

a)

10

b)

11

c)

12

d)

9

13.

How many times will this loop run? for i in range(3): print(i)

a)

2

b)

3

c)

4

d)

0

14.

What is the output of: for i in range(2, 5): print(i)

a)

2, 3, 4

b)

2, 3, 4, 5

c)

3, 4, 5

d)

None

15.

What does range(5, 10, 2) produce?

a)

5, 6, 7, 8, 9

b)

5, 7, 9

c)

6, 8, 10

d)

5, 10

16.

What is the output of the following function? def greet(): print('Hello') greet()

a)

Hello

b)

Error

c)

None

d)

greet

17.

What does this function return? def add(a, b): return a + b print(add(2, 3))

a)

2

b)

3

c)

5

d)

Error

18.

Which is a correct function definition?

a)

def my_function a, b):

b)

def my_function(a, b):

c)

function my_function(a, b):

d)

my_function def(a, b):

19.

What is the output of: def repeat(word): return word * 2 print(repeat('Hi'))

a)

HiHi

b)

Hi Hi

c)

Hi2

d)

Error

20.

What will the following code output? print('Python'[2])

a)

P

b)

y

c)

t

d)

h

21.

What does len('Hello World') return?

a)

10

b)

11

c)

12

d)

9

22.

What is the output of 'Hello' + ' ' + 'World'?

a)

Hello World

b)

HelloWorld

c)

Error

d)

Hello

23.

How many times will this loop run? for i in range(3): print(i)

a)

2

b)

3

c)

4

d)

0

24.

What is the output of: for i in range(2, 5): print(i)

a)

2, 3, 4

b)

2, 3, 4, 5

c)

3, 4, 5

d)

None