NEW
Font size
WorksheetsPython Programming Revision
Total questions: 23
Worksheet time: 12mins
What is the syntax for an if statement in Python?
if [condition]
if (condition)
if {condition}
if condition:
Which loop in Python is used to iterate over a sequence of elements?
for
do-while
if
while
What is the purpose of a function in Python?
The purpose of a function in Python is to execute a single line of code.
The purpose of a function in Python is to create a loop.
The purpose of a function in Python is to encapsulate a set of instructions or code into a reusable block.
The purpose of a function in Python is to print a message to the console.
How do you declare a variable in Python?
By using the division operator (/)
By using the addition operator (+)
By using the multiplication operator (*)
By using the assignment operator (=)
What is the data type of the variable 'x' in the following code: x = 5
float
integer
string
boolean
What is the result of the following expression: 10 > 5
true
false
10
5
What is the keyword used to define a function in Python?
function
def
var
class
What is the output of the following code: print('Hello, World!')
Hello
World
print('Hello, World!')
Hello, World!
What is the data type of the variable 'name' in the following code: name = 'John'
integer
boolean
float
string
What is the output of the following Python code: print(5 + 3)
8
53
5 + 3
None of the above
What is the data type of the variable 'pi' in the following code: pi = 3.14
integer
float
string
boolean
What keyword is used to halt a function and go back to the calling code?
stop
base case
quit
return
Every time you _ a function, the indented statements are run.
return
use
call
Which function has the correct function syntax?
What is the output?
None
98
17
72
How to create a function in Python
def myFunction():
create myFunction():
define myFunction():
make myFunction():
You assign a value to a variable with which symbol
@
==
=
*
What is the output from the following code:
[3,2,6,1,Dave]
[Dave,3,2,6,1]
[3,2,6,1,'Dave']
['Dave',3,2,6,1]
What does the following code output?
11, 9
16, 16
None, None
225, 117
Which of the following is the correct code to define a function?
def area ( ):
area ( )
def area:
def area ( )
