WorksheetsPython review wk 1 to 5
Total questions: 38
Worksheet time: 14mins
What will this print to the screen?
print (2 * 4)
2 * 4
8
error
nothing will be printed
What will be printed to the screen?
x = 5
y = "John"
print (x + y)
5 + John
John
JohnJohnJohnJohnJohn
Syntax error - you cannot add str and int together
What which of the following is a valid naming convention for a variable?
waterBottle
WaterBottle
water_bottle
WATER_BOTTLE
Which of the following is a valid identifier in Python?
_two_percent
return
2_PERCENT
while
Which of the following data type is the postal_code?
postal_code = "555123"
string
int
float
boolean
A special type of loop that never ends?
Infinite loop
Recursive loop
Nested loop
Unconditional loop
The equivalent of the above for loop using the while syntax would be
The process of giving a value to a variable?
Assignment
Initialisation
Coercion
Declaration
In python which is the correct method to load a module math?
include math
import math
#include<math.h>
using math
What will be the printed result for the following codes?
radius = input("Enter the radius of the circle: ")
radius = 3.0
area_of_circle = 3.142 * radius * radius
print("Area is: ", area_of_circle)
Area is 28.278
SyntaxError: * operator cannot be use in this case
TypeError: int cannot be multiply by float
TypeError: float cannot be multiply by str
A variable declared inside the function’s body is known as
Function scope
Global scope
Conditional scope
Local scope
What is the issue with the following code?
If condition will never be fulfil
print cannot be use multiple times
age is always lesser or equals to 18
Printing conflicting statement,, should have an else statement
What is the issue with the following code?
age 18 should already be an adult
no if statement, compile error SyntaxError
missing elif statement
invalid print statement within else condition
What is the issue with the following code?
SyntaxError, missing " : " at if statement condition
should be elif instead of else
missing condition after else
age is an invalid variable
What is the issue with the following code?
SyntaxError, invalid condition
NameError, variable sale is not defined
Logical error, sale will never be more than 20
Logical error. condition "sale >= 20 or sale <= 20" will always fulfilled
FOR loops are
loops which run an unknown number of times
loops that iterates over a sequence in Python
loops which run a known number of times
repeatedly execute a statement as long as the condition provided stays true
WHILE loops are
loops which run an unknown number of times
repeatedly execute a statement as long as the condition provided stays true
loops that iterates over a sequence in Python
loops which run a known number of times
numbers = [2, 4, 6, 8]
for number in numbers:
print("hello!")
2 hello! 4 hello! 6 hello! 8 hello!
hello!
2 4 6 8
hello! hello! hello! hello!
which of the following is a valid naming convention for a constant?
SHOE_SIZE
shoe_size
shoeSize
ShoeSize
Which function is called anonymous function?
Define
Function
Recursion
Lambda
The program above prints
Numbers between 1 and 100 that are multiples of 5
Numbers between 1 and 100
Numbers between 1 and 100 divisible by 5
Numbers between 1 and 101 that are multiples of 5
What is the output of the given code?
10 20 10
10
20
10 20
If return statement is not used inside the function, the function will return:
TypeError: All functions need a return statement
0
Null
None
Use the correct order of operations to evaluate this expression ...
6 * 8 / 2 + (15 - 6) + 3 ^ 2
42
32
52
72
Example of ...?
Nested loop
Nested selection
Recursion
Sequence
What is the issue with the following code?
NameError,
True is a reserved word and cannot be use
SyntaxError,
If statement requires a condition rather than True
LogicalError,
Last print statement will always be printed
LogicalError,
The else statement will never be printed
__________ keyword is used for creating a function in Python.
define
fun
def
function
for i in range(1, 6):
if i == 3:
continue
print(i, end=",")
What would be the output of the code above?
1,2,3,4,5,
1,2,4,5
1,2,4,5,
Error
numbers = [5, 14, 9, 17]
for number in numbers:
if number % 3 == 0:
print(number)
The output will be?
17
9
14
9
17
14
17
Python supports variable number of parameters.
True
False
Select the advantages of functions
Modular programming
Code re-usability
Improving clarity of the code
All the above
Why is the following variable name invalid:
1st_Name
No special characters other than underscore
The variable name starts with a number
Keep names meaningful
There is nothing wrong with this variable name
Which of the following import only parts of a module instead of a whole module?
from math import pi
import math
from math import *
start importing math
To loop through a set of code a specified number of times, which of the following function can we use?
range()
float()
print()
input()
What is the output of the given code?
10 20 10 20
10 20 10
10 20 20
Error
List items are indexed, the first item has index [1], the second item has index [2] etc.
True
False
Which of these pieces of code would return the name "Harry" from the following list?
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList()
nameList[1]
nameList["4"]
Given the following code, what would be the result?
def test():
return 'abc', 100
result = test()
print(result[0])
print(result[1])
SyntaxError: Unable to return more than 1 value
result[0]
result[1]
abc
100
abc 100
abc 100
