WorksheetsSubprograms & if statements
Total questions: 44
Worksheet time: 23mins
Which of the following is the correct way to write a basic if statement in Python to check if a variable `age` is greater than 14?
if age > 14 then:
if age > 14:
if (age > 14)
if age => 14:
What does the following if statement do? ```python if temperature < 0: print("It's freezing!") ```
Prints "It's freezing!" if the temperature is above 0°C
Prints "It's freezing!" if the temperature is below 0°C
Prints "It's freezing!" if the temperature is exactly 0°C
Always prints "It's freezing!"
Which of these is a comparative operator used in if statements?
++
==
&&
**
What will be printed by the following code?
Passed
Failed
Nothing
Error
Which of the following is NOT a valid comparative operator in Python?
>
!=
=>
<=
What is the error in this if statement?
The colon is missing
The comparison operator should be ==
The print statement is incorrect
There is no error
Which of the following if statements checks if the variable `weight` is less than 10 kg?
if weight < 10:
if weight < 10kg:
if weight > 10:
if weight == 10:
What will the following code output?
Not ten
10
Nothing
Error
Which of these is a common mistake when writing if statements in Python?
Using a colon at the end of the if line
Using = instead of == for comparison
Indenting the code after the if statement
Using comparative operators
What does the following code do?
Prints "False"
Prints "True"
Prints both "True" and "False"
Generates an error
Which of the following will check if the variable `distance` is exactly 1 mile?
if distance = 1:
if distance == 1:
if distance != 1:
if distance > 1:
What is the output of this code?
Hot
Not hot
20
Error
Which of the following is the correct way to check if `ounces` is not equal to 16?
if ounces != 16:
if ounces <> 16:
if ounces =! 16:
if ounces not 16:
What will happen if you forget to indent the code after an if statement in Python?
The code will run as normal
Python will give an IndentationError
The if statement will be ignored
The code will print twice
Which of these if statements will check if `marks` is less than or equal to 40?
if marks < 40:
if marks <= 40:
if marks => 40:
if marks == 40:
What is wrong with this if statement?
The colon is missing at the end of the if line
The brackets are not allowed
Missing indentation
There is nothing wrong
Which of the following will check if `volume` is exactly 8 ounces?
if volume == 8:
if volume = 8:
if volume != 8:
if volume > 8:
What will the following code?
Too fast
Safe speed
30
Error
Which of these is the correct way to check if `length` is not equal to 1 metre?
if length != 1:
if length =! 1:
if length <> 1:
if length not 1:
Which of the following is the correct way to assign the value 5 to a variable called `apples` in Python?
apples == 5
apples = 5
5 = apples
apples := 5
What will be the value of `total` after the following code runs?
2
3
5
6
Which of these variable names is NOT valid in Python?
my_score
2ndPlace
totalMarks
student_name
What is the value of `y` after this code runs?
7
2
14
9
What type of value is stored in the variable `name` after this code? ```python name = "Alice" ```
Integer
String
Boolean
Float
Which of the following is the correct way to increase the value of `count` by 1?
count =+ 1
count = count + 1
count == count + 1
count := 1
What will be printed by the following code?
7
12
43
1
Which of the following is the correct way to get input from a user and store it in a variable called `name`?
name = input("Enter your name: ")
input = name("Enter your name: ")
name == input("Enter your name: ")
name := input("Enter your name: ")
If you want to ask the user for their age and store it as an integer in the variable `age`, which code should you use?
age = input("Enter your age: ")
age = int(input("Enter your age: "))
age = str(input("Enter your age: "))
age = float(input("Enter your age: "))
What will be the type of the variable `number` after this code runs? ```python number = input("Type a number: ") ```
Integer
String
Float
Boolean
What will be printed if the user enters `7` for the following code?
10
73
Error
3
Which of the following will cause an error if the user enters the word `ten`?
age = input("Enter your age: ")
age = int(input("Enter your age: "))
name = input("Enter your name: ")
colour = input("Enter your favourite colour: ")
What is wrong with this code?
Nothing
Colon
Assignment Operator
Indentation
Something else.
How many variables are in this subprogram?
3
4
1
2
Identify the name of this subprogram:
def
values
error
values( )
On which line does this program call the subprogram 'values'?
1
1,2,3,4
6
The program is not correctly called.
'def' is short for?
(a)
What will happen when you run this program
It will call a subprogram that asks you to enter two integers, then output each of these.
It will define and call a subprogram that asks you to enter two integers, then output each of these.
It will generate an error due to missing assignment operators.
It will generate an error due to something else.
Which subprogram runs first?
'welcome' then 'goodbye'
'goodbye' then 'welcome'
Neither - programs are not correctly called.
Error for a different reason.
What software do we use when programming? (Use capital letters)
(a)
True or False? You can change values stored in a variable.
True
False
Sometimes
True or False? Variables can be declared within and outside of a subprogram.
True
False
Yes but only using 'global'
True or False? int( ) is used for casting.
True
False - it is used for turning something into an integer
False - it is used for a different reason.
True or False? You can only create three internal subprograms.
True
False
Depends on memory.
Subprograms are an example of
Abstraction
Decomposition
Algorithmic Thinking
Computational Thinking
