Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python challenge by Grade 8a Billabong Group

Total questions: 20

Worksheet time: 4mins

Name
Class
Date
1.

What does a for loop do in Python?

a)

Repeats a block of code

b)

Runs code only once

c)

Creates a function

d)

Stops the program

2.

Which keyword is used to define a function?

a)

func

b)

define

c)

def

d)

function

3.

What is the correct way to access the 2nd item in a list?

fruits = ["apple", "banana", "mango"]

a)

fruits[0]

b)

fruits[1]

c)

fruits(1)

d)

fruits{2}

4.

What will be the output?

for i in range(3):

print("Hi")

a)

Hi

b)

HiHiHi

c)

Hi (printed three times)

d)

Error

5.

Which is a string in Python?

a)

"Hello"

b)

56

c)

True

d)

[1, 2, 3]

6.

Which of these adds an item to a list?

a)

list.add()

b)

list.append()

c)

list.put()

d)

list.insert() only

7.

What does len("Python") return?

a)

5

b)

6

c)

PYTHON

d)

Error

8.

A (a)   loop continues until a condition becomes false.

9.

A function returns a value using the (a)   keyword.

10.

Strings in Python are surrounded by ______ or ______.

(a)  

11.

The index of the first element in a list is (a)   .

12.

The command used to repeat code a fixed number of times is (a)   .

13.

What will this print?

name = "Computer"

print(name[2])

a)

Computer

b)

Error

c)

Computer Computer

d)

n

14.

fruits = ["a", "b", "c", "d"]

print(fruits[-1])

a)

a

b)

b

c)

c

d)

d

15.

def greet():

return "Hello!"

print(greet())

a)

Hello!

b)

Error

c)

greet Hello

d)

"Hello!"

16.

for i in range(1, 4):

print(i)

a)

1

2

3

b)

1

2

3

4

c)

1

2

d)

Error

17.

text = "hello"

print(text.upper())

a)

Error

b)

hello

c)

"hello"

d)

HELLO

18.

Write a Python function named add that takes two numbers and returns their sum.

a)

def add(a, b):

return a + b

b)

def add(a, b)

return a + b

c)

def add(a, b)

return a + b:

d)

def add(a, b):

return a + b

19.

Write a loop that prints numbers from 1 to 5.

a)

for i in range(1, 6):

print(i)

b)

for i in range(1, 5):

print(i)

c)

for i in range(1, 6):

print(I)

d)

for i in range(1, 6):

print(i)

20.

Write a list of any 3 colors and print the first item.

a)

colors = ["red", "blue", "green"]

print(colors1)

b)

colors = ["red", "blue", "green"]

print(colors[0])

c)

colors = ["red, "blue", "green"]

print(colors[0])

d)

colors = ["red", "blue" "green")

print(colors[0])