WorksheetsGrade 6 Revision - Unit 3 Python
Total questions: 70
Worksheet time: 35mins
How can you print multiple values on the same line in Python?
Using the print() function with multiple arguments
Using the input() function with multiple arguments
Using the format() function to concatenate strings
Both a and c
How can you get input from the user and store it in multiple variables in Python?
Using the input() function with multiple arguments
Using the input() function with a comma-separated list of variable names
Using the input() function and splitting the input by a specified separator
Both b and c
Which of the following is not a valid assignment operator in Python?
=
+=
-=
**=
What is the purpose of the assignment operators in Python?
To perform mathematical operations on operands
To compare operands
To assign values to variables
To manipulate the logical state of operands
What is the purpose of the arithmetic operators in Python?
To perform mathematical operations on operands
To compare operands
To assign values to variables
To manipulate the logical state of operands
What data type is the input from the user in Python by default?
Integer
Float
String
Boolean
Which keyword do you use to start a for loop in Python?
for
while
if
repeat
What is the purpose of the comparison operators in Python?
To perform mathematical operations on operands
To compare operands
To assign values to variables
To manipulate the logical state of operands
What word do you use to start an if statement in Python?
if
then
else
switch
Which of these is the correct way to write an if statement in Python?
if (condition):
code
if condition:
code
if (condition) then:
code
if condition then:
code
What is the purpose of the logical operators in Python?
To perform mathematical operations on operands
To compare operands
To assign values to variables
To manipulate the logical state of operands
Which of these is the correct way to write an if-else statement in Python?
if (condition):
code
else: code
if condition then:
code
else:
code
if (condition) then: code
else:
code
if condition:
code
else:
code
What does the range() function do in a for loop in Python?
It sets the start and end of the loop
It sets the step size of the loop
It creates a list of numbers to loop through
Both a and c
Which of these is a common way to exit a while loop?
Using the break statement
Using the continue statement
Using the return statement
All of the above
How can you exit a for loop early in Python?
by using the break keyword
by using the continue keyword
by using the return keyword
by using the exit() function
What is the purpose of a while loop?
To execute a block of code a specific number of times
To execute a block of code until a certain condition is met
To execute a block of code for each item in a list
To execute a block of code only once
How can you combine multiple conditions in an if statement in Python?
Use the and and or operators
Use the if, elif, and else keywords
Use the switch statement
Both a and b
What happens if the condition in an if statement is false?
The code inside the if statement runs
The code inside the if statement does not run
An error happens
The program stops
Which of the following is the correct syntax for a while loop in Python?
for i in range(10):
while i < 10:
if i < 10:
while i:
What does the not operator do in Python?
It makes the statement true if the condition is true
It makes the statement false if the condition is true
It makes the statement true if the condition is false
It makes the statement false if the condition is false
What is the purpose of the elif statement in an if statement in Python?
To run a piece of code if the previous condition is true
To run a piece of code if the previous condition is false
To add another condition to the if statement
To stop the if statement
What is the result of the expression 5 > 3 or 2 > 4 in Python?
True
False
1
0
What is the purpose of the else statement in an if statement in Python?
To run a piece of code if the previous condition is true
To run a piece of code if the previous condition is false
To add another condition to the if statement
To stop the if statement
What is the purpose of an if statement in Python?
To run a piece of code if a condition is true
To run a piece of code if a condition is false
To repeat a piece of code
To create a function
What happens if the condition in a while loop is always True?
The loop will execute once and then stop
The loop will never execute
The loop will execute indefinitely
The loop will execute 10 times
What is the purpose of an if-else statement?
To execute a block of code only if a certain condition is true
To execute a block of code a specific number of times
To create a loop that continues until a certain condition is met
Both a) and c)
Which of the following is not a valid comparison operator in Python?
>
=
>=
!=
What does the and operator do in Python?
It makes the statement true if both parts are true
It makes the statement true if at least one part is true
It makes the statement false if both parts are false
Both a and c
How can you make a for loop go through a list in Python?
by using the range() function
by using the list() function
by using the for i in list_name: syntax
by using the for each keyword
Which of these statements is true about the condition in a while loop?
The condition must be a numerical value
The condition must be a boolean expression
The condition must be a string
The condition can be any type of expression
What is the result of the expression 10 / 3 in Python?
3
3.0
3.33
3.333333333
Which of the following is the correct way to get input from the user in Python?
x = input("Enter a number: ")
x = input(Enter a number: )
x = input(int("Enter a number: "))
Both a and c
What is the purpose of a for loop in Python?
To run a piece of code once
To run a piece of code a certain number of times
To run a piece of code until a condition is met
To create a function
What is the result of the expression 5 > 3 and 2 < 4 in Python?
True
False
1
0
What is the result of the expression for i in range(3) in Python?
The loop runs 0 times
The loop runs 1 time
The loop runs 3 times
The loop runs 4 times
How can you add another condition to an if statement in Python?
Use the else keyword
Use the elseif keyword
Use the elif keyword
Use the otherwise keyword
When would you use logical operators in a Python program?
When you need to check if multiple conditions are true
When you need to check if at least one condition is true
When you need to check if a condition is false
All of the above
Which of the following is not a valid arithmetic operator in Python?
+
-
*
%/
What does the or operator do in Python?
It makes the statement true if both parts are true
It makes the statement true if at least one part is true
It makes the statement false if both parts are false
Both b and c
What is the purpose of a for loop in Python?
To run a piece of code once
To run a piece of code a certain number of times
To run a piece of code until a condition is met
To create a function
How many times will the code inside a for loop run if the loop goes from 0 to 4?
0 times
1 time
4 times
5 times
What is the correct way to write a for loop in Python?
for i = 0 to 5:
code
for (i = 0; i < 5; i++):
code
for i in range(5):
code
for i from 0 to 5:
code
What happens if the condition in an if statement is False?
The code block inside the if statement will be executed
The code block inside the else statement will be executed
Nothing happens, the program will continue to the next line
The program will crash
What is the result of the expression x = 5; x += 2 in Python?
x = 7
x = 2
x = 10
x = 5
What is the name of the the programming language you learned in Unit 3?
Java
C++
Python
JavaScript
Which of the following is the correct syntax for an if-else statement in Python?
if condition:
# code block
else:
# code block
if (condition):
# code block
else:
# code block
if condition:
# code block
else
if condition:
# code block
if (condition):
# code block
elif condition:
# code block
else:
# code block
What is the purpose of the len() function in Python?
To get the length of a string
To perform mathematical calculations
To display output on the screen
To get input from the user
What is the output of the following code?
1 1
1 2
2 1
2 2
3 1
3 2
1 1
1 2
2 1
2 2
3 1
3 2
3 3
1 1
1 2
2 1
2 2
3 1
3 3
1 1
2 1
3 1
What is the operator used to perform addition in Python?
+
-
*
/
What is a variable in Python?
A container that stores a value
A block of code that can be reused
A way to display output on the screen
A way to get input from the user
What is the output of the following code?
Positive
Negative
Zero
No output
Which of these is a data type in Python?
Integer
String
Boolean
All of the above
What is the purpose of the print() function in Python?
To store a value in a variable
To perform mathematical calculations
To display output on the screen
To get input from the user
What function is used to get input from the user in Python?
print()
input()
output()
read()
Which of these can be used as a condition in an if-else statement?
A numerical value
A boolean expression
A string
All of the above
What is the purpose of a comment in Python code?
To explain what the code does
To make the code run faster
To change the behavior of the code
To display output on the screen
What is the purpose of the elif statement in an if-else statement?
To check an additional condition if the first condition is False
To create a loop that continues until a certain condition is met
To execute a block of code a specific number of times
To create a nested if-else statement
Which of these is a valid variable name in Python?
my_variable
1_variable
variable-name
both a) and b)
What is the correct way to define a function in Python?
function my_function()
def my_function()
create my_function()
function: my_function()
How can you check if two conditions are both true in an if-else statement?
Use the and operator
Use the or operator
Use the not operator
Use the ==operator
What is the output of the following code?
You can vote!
You can't vote yet.
No output
Both a) and b)
Suppose you want to check if a number is even or odd. Which of these if-else statements would be the best way to do this?
if num % 2 == 0: print("Even")
else:
print("Odd")
if num % 2: print("Odd")
else:
print("Even")
if num % 2 == 1: print("Odd")
else:
print("Even")
Both a) and c)
Which of these is a good use case for an if-else statement?
Checking the user's age to determine if they can vote
Calculating the area of a circle
Iterating through a list of numbers
Both a) and b)
Which of the following shapes is commonly used to represent a decision or branch in a Python flowchart?
Oval
Rectangle
Diamond
Parallelogram
Which of the following Python statements is typically represented by the "process" shape in a flowchart?
If-else statement
For loop
Function call
All of the above
In a Python flowchart, what does the "terminator" shape (e.g., oval) typically represent?
The start or end of the program
A decision point
A process or operation
Input/output
Which of the following symbols is used to represent the input or output of data in a Python flowchart?
Rectangle
Parallelogram
Diamond
Cylinder
How can a Python flowchart help in the debugging process?
It can identify logic errors in the code
It can speed up the execution of the program
It can automatically fix errors in the code
It can generate test cases
What is the main advantage of using a flowchart in Python programming?
It makes the code more concise
It improves the readability and understanding of the program
It reduces the need for comments in the code
It automatically optimizes the program's performance
Which of the following Python constructs is typically represented by a decision shape (e.g., diamond) in a flowchart?
Variable assignment
Function definition
If-elif-else statements
Print statements
