Font size
WorksheetsYear 9 Python Programming
Total questions: 47
Worksheet time: 28mins
Which command will display the text 'Hello world!' on the screen?
print(Hello world!)
print "Hello world!"
print("Hello world!")
print = "Hello world!"
Which command will correctly ask the user for their age?
age = input("How old are you?")
age = input(How old are you?)
input("How old are you?") = age
How old are you = input()
Which decision statement will be triggered if the variable x is less than 20?
if x > 20:
if x <> 20:
if x == 20:
if x < 20:
Which of these tests whether the variable x is the same as 'Hello'?
x = "Hello"
x != "Hello"
x == "Hello"
x <> "Hello"
What is the output of the following program?
Yes
No
Error
No output
What is the output of the following program?
Yes
No
Error
No output
What is the output of the following program?
1 to 10 numbers
1 to 5 numbers
1
5
What would the output of this code be if the user entered the value 70?
Pass
Fail
Merit
Distinction
What is the output of this code?
Error
No Output
x is 10
x is not 10
What is the output of this code?
Both conditions are true
At least one condition is false
Error
No Output
What is the output of this code?
5
10
15
Error
What is the data type of the variable 'x' in the following code? x = 5.5
int
float
string
boolean
What is the correct way to define a function in Python?
def myFunction()
function myFunction()
myFunction()
function myFunction:
Which of the following is not a valid comparison operator in Python?
==
!=
<=
><
1. In programming sequence, instructions are run in what order?
bottom to top
randomly
in the order they are presented
What do we use variables for?
To store data
Print data
Produce functions
In python the ' boolean' data type can be defined as...?
holds alphanumerical data
holds whole numbers
holds a number with a decimal point
holds either true or false
Which of the following is used to define a block of code in Python language?
Key
Brackets
Indentation
None of the above
Which loop structure is used to iterate over a sequence of items?
for loop
while loop
do-while loop
if loop
Which of the following is an example of a variable in Python?
print("hello")
age=13
input("Enter your age")
type()
a = 10
b=5
b=a+5
print(b)
What would be printed to the screen in this example?
5
10
105
15
a = 10
b=5
b=a+5
print(a)
What would be printed to the screen in this example?
5
10
105
15
FOR loops are
loops which run an unknown number of times
loops which run for a specific number of times
the same as if statements
not part of programming
In programming, what is iteration?
The repetition of steps within a program
The order in which instructions are carried out
A decision point in a program
Testing a program to make sure it works
Which of the following is an example of a variable in Python?
print("hello")
age=13
input("Enter your age")
type()
a = 10
b=5
b=a+5
print(b)
What would be printed to the screen in this example?
5
10
105
15
a = 10
b=5
b=a+5
print(a+b)
What would be printed to the screen in this example?
5
10
25
15
FOR loops are
loops which run an unknown number of times
loops which run for a specific number of times
the same as if statements
not part of programming
This loop can only be used when the programmer knows the number of times a code is to be repeated
while
for
do while
repeat until
In programming, what is iteration?
The repetition of steps within a program
The order in which instructions are carried out
A decision point in a program
Testing a program to make sure it works
Why is iteration important?
It determines the order in which instructions are carried out
It allows code to be simplified by removing duplicated steps
It allows multiple paths through a program
It ensures the code works correctly
What does the following program display?
1,2,3,4
1,2,3,4,5
counter,counter,counter,counter,counter
0,1,2,3,4,5
What does the program display as its output?
1,2,3,4
Python uses indentation to block code into chunks
True
False
Code for Hello, World!
print Hello, World!
print("Hello, World!)
print("Hello, World!")
What datatype will the answer be if the user enters 15 and 30?
Integer
String
Boolean
Float
Code for
Five is greater than two!
if 5 > 2:
print("Five is greater than two!")
if 5 = 2:
print("Five is greater than two!")
if 5 > 2: Print("Five is greater than two!")
Write the four mathematical symbols for python (4 points)
The program above
prints all the odd numbers between 1 and 20
prints all even numbers between 1 and 20
print all the odd numbers between 1 and 21
prints all the even numbers between 1 and 21
The equivalent of the above for loop using the while syntax would be
