wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Year 9 Python Programming

Total questions: 47

Worksheet time: 28mins

Name
Class
Date
1.

Which command will display the text 'Hello world!' on the screen?

a)

print(Hello world!)

b)

print "Hello world!"

c)

print("Hello world!")

d)

print = "Hello world!"

2.

Which command will correctly ask the user for their age?

a)

age = input("How old are you?")

b)

age = input(How old are you?)

c)

input("How old are you?") = age

d)

How old are you = input()

3.

Which decision statement will be triggered if the variable x is less than 20?

a)

if x > 20:

b)

if x <> 20:

c)

if x == 20:

d)

if x < 20:

4.

Which of these tests whether the variable x is the same as 'Hello'?

a)

x = "Hello"

b)

x != "Hello"

c)

x == "Hello"

d)

x <> "Hello"

5.

What is the output of the following program?

a)

Yes

b)

No

c)

Error

d)

No output

6.

What is the output of the following program?

a)

Yes

b)

No

c)

Error

d)

No output

7.

What is the output of the following program?

a)

1 to 10 numbers

b)

1 to 5 numbers

c)

1

d)

5

8.

What would the output of this code be if the user entered the value 70?

a)

Pass

b)

Fail

c)

Merit

d)

Distinction

9.

What is the output of this code?

a)

Error

b)

No Output

c)

x is 10

d)

x is not 10

10.

What is the output of this code?

a)

Both conditions are true

b)

At least one condition is false

c)

Error

d)

No Output

11.

What is the output of this code?

a)

5

b)

10

c)

15

d)

Error

12.

What is the data type of the variable 'x' in the following code? x = 5.5

a)

int

b)

float

c)

string

d)

boolean

13.

What is the correct way to define a function in Python?

a)

def myFunction()

b)

function myFunction()

c)

myFunction()

d)

function myFunction:

14.

Which of the following is not a valid comparison operator in Python?

a)

==

b)

!=

c)

<=

d)

><

15.

1. In programming sequence, instructions are run in what order?

a)

bottom to top

b)

randomly

c)

in the order they are presented

16.

What do we use variables for?

a)

To store data

b)

Print data

c)

Produce functions

17.

In python the ' boolean' data type can be defined as...?

a)

holds alphanumerical data

b)

holds whole numbers

c)

holds a number with a decimal point

d)

holds either true or false

18.

Which of the following is used to define a block of code in Python language?

a)

Key

b)

Brackets

c)

Indentation

d)

None of the above

19.

Which loop structure is used to iterate over a sequence of items?

a)

for loop

b)

while loop

c)

do-while loop

d)

if loop

20.

Which of the following is an example of a variable in Python?

a)

print("hello")

b)

age=13

c)

input("Enter your age")

d)

type()

21.

a = 10

b=5

b=a+5

print(b)

What would be printed to the screen in this example?

a)

5

b)

10

c)

105

d)

15

22.

a = 10

b=5

b=a+5

print(a)

What would be printed to the screen in this example?

a)

5

b)

10

c)

105

d)

15

23.

FOR loops are

a)

loops which run an unknown number of times

b)

loops which run for a specific number of times

c)

the same as if statements

d)

not part of programming

24.

In programming, what is iteration?

a)

The repetition of steps within a program

b)

The order in which instructions are carried out

c)

A decision point in a program

d)

Testing a program to make sure it works

25.

Which of the following is an example of a variable in Python?

a)

print("hello")

b)

age=13

c)

input("Enter your age")

d)

type()

26.

a = 10

b=5

b=a+5

print(b)

What would be printed to the screen in this example?

a)

5

b)

10

c)

105

d)

15

27.

a = 10

b=5

b=a+5

print(a+b)

What would be printed to the screen in this example?

a)

5

b)

10

c)

25

d)

15

28.

FOR loops are

a)

loops which run an unknown number of times

b)

loops which run for a specific number of times

c)

the same as if statements

d)

not part of programming

29.

This loop can only be used when the programmer knows the number of times a code is to be repeated

a)

while

b)

for

c)

do while

d)

repeat until

30.

In programming, what is iteration?

a)

The repetition of steps within a program

b)

The order in which instructions are carried out

c)

A decision point in a program

d)

Testing a program to make sure it works

31.

Why is iteration important?

a)

It determines the order in which instructions are carried out

b)

It allows code to be simplified by removing duplicated steps

c)

It allows multiple paths through a program

d)

It ensures the code works correctly

32.

What does the following program display?

a)

1,2,3,4

b)

1,2,3,4,5

c)

counter,counter,counter,counter,counter

d)

0,1,2,3,4,5

33.

What does the program display as its output?

a)
b)
c)
d)

1,2,3,4

34.

Python uses indentation to block code into chunks

a)

True

b)

False

35.
What is the word (command) used to display numbers and text on the screen?
a)
print
b)
input
c)
output
d)
command
36.
What is a variable?
a)
A box(memory location) where you store values
b)
a type of graphics
c)
Data type
d)
a type of memory
37.
What symbol is used in python to assign values to a variable?
a)
equals =
b)
plus + 
c)
forward slash /
d)
asterisk *
38.
When you have an error in your code what is the term to summarise finding and fixing that error?
a)
Error checking
b)
Debugging
c)
Syntax finder
d)
Error finder
39.
What is Python?
a)
text based programming language
b)
word processor 
c)
spreadsheet
d)
block based programming language
40.
What Python command lets the user enter an answer to a question?
a)
answer()
b)
open()
c)
print()
d)
input()
41.

Code for Hello, World!

a)

print Hello, World!

b)

print("Hello, World!)

c)

print("Hello, World!")

42.
What does the term 'debug' mean?
a)
Identify errors and fix them.
b)
Making a calculation
c)
A set of instructions
d)
Looking at code
43.

What datatype will the answer be if the user enters 15 and 30?

a)

Integer

b)

String

c)

Boolean

d)

Float

44.

Code for

Five is greater than two!

a)

if 5 > 2:

print("Five is greater than two!")

b)

if 5 = 2:

print("Five is greater than two!")

c)

if 5 > 2: Print("Five is greater than two!")

45.

Write the four mathematical symbols for python (4 points)

4 lines
46.

The program above

a)

prints all the odd numbers between 1 and 20

b)

prints all even numbers between 1 and 20

c)

print all the odd numbers between 1 and 21

d)

prints all the even numbers between 1 and 21

47.

The equivalent of the above for loop using the while syntax would be

a)
b)
c)
d)