Font size
WorksheetsPython Mixed Concepts
Total questions: 78
Worksheet time: 41mins
What value is printed to the console?
13
4
22
17
-2
What is printed to the console?
13
4
17
22
What value is printed to console?
22
17
-2
4
thisList = ["square", "circle", "triangle", "octagon"]
print(thisList[3])
octagon
triangle
circle
square
num = [1, 2, 3, 4]
num.append(0)
print(num)
What is the output?
[0,1,2,3,4]
[1,2,3,4,5]
[0,1,2,3]
[1,2,3,4,0]
What is the result of the expression [x*2 for x in range(5)]?
[0, 1, 2, 3, 4]
[2, 4, 6, 8, 10]
[1, 4, 9, 16, 25]
[0, 2, 4, 6, 8]
What is the difference between append() and extend() methods in Python lists?
The append() method adds multiple elements to the end of the list, while the extend() method adds a single element to the end of the list.
The append() method removes elements from the list, while the extend() method adds elements to the list.
The append() method adds a single element to the end of the list, while the extend() method adds multiple elements to the end of the list.
The append() method adds elements to the beginning of the list, while the extend() method adds elements to the middle of the list.
How do you access the second element of the first list in a nested list named 'my_nested_list'?
my_nested_list[0,1]
my_nested_list[0][1]
my_nested_list[2][1]
my_nested_list[1][0]
Lists are used to store single item in a single variable.
True
False
List items are ordered, changeable, and allow duplicate values.
True
False
List items are indexed, the first item has index [1], the second item has index [2] etc.
True
False
When we say that lists are ordered, it means that the items have a defined order, and that order will not change.
True
False
List items can be of any data type:
True
False
If you add new items to a list, the new items will be placed at the end of the list.
True
False
Which of these is the correct code for creating a list of names?
nameList = John, Harry, Jesse, John, Harry, Harry
nameList = ("John", "Harry", "Jesse", "John", "Harry", "Harry")
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList = [John, Harry, Jesse, John, Harry, Harry]
List items have an index number. In the following list, which item has the index number of 3?
["John", "Harry", "Jesse", "John", "Harry", "Harry"]
"John"
"Harry"
"Jesse"
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)
nameList["4"]
The list needs one more name added to the end - "Felipe". Which piece of code below would do this?
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList.append(Felipe)
append(nameList,"Felipe")
nameList.append["Felipe",7]
nameList.append("Felipe")
Is this the correct code for a list?
register = {"Sam", "Pheobe", Georgia", Richard"}
Yes
No
The count() method returns the number of times the specified element appears in the list.
What is the output of this code?
3
2
1
0
Output of this code?
[2,4,6,8,10]
['2','4','6','8','10']
[0,2,4,6,8]
[10,8,6,4,2]
What is the index of “grape” in the list
[“apple”, “grape”, “orange”, “watermelon”]?
0
1
2
3
The program snippet above is syntactically correct
False
True
You should be at least 18 years to vote. What should be the expression in the if statement that will print
can vote.
age >= 18
age = 18
age == 18
What is the output of the program above.
can vote
can drink
can vote can drink
What is the output of the above program
can vote
can drink
can vote
can drink
none of the above
What is the output of the code above
go watch cartoons
can vote
go get a girlfriend/boyfriend
For which value of age, will the output "go drink" get printed
It will never print
17
22
The program above will print
Nothing
tends to drink
tends to chitchat
The code above will print
python
java
None
Consider the Python code snippet shown.
What is the value of the 'total' variable after this code is executed?
0
3
6
10
In Python, what is the purpose of the "break" statement in a loop?
It skips the current iteration and continues to the next one
It exits the loop prematurely
It prints a message to the console
It restarts the loop from the beginning
Consider the code snippet shown.
What will be the output of this code?
5, 4, 3
5, 4, 3, 2
5, 4, 3, 2, 1
2, 1
Which of the following is not a comparison operator in Python?
==
<=
&&
>
Consider the code snippet shown.
What will be the output of this code?
1,2,3
1,2,3,4
1,2,3,4,5,6
1,2,3,2,4,3
What does the "continue" statement do in a loop in Python?
Exits the loop
Skips the remining code in current iteration and starts the next one
Starts a new iteration
Raises an error
Consider the following code snippet.
What will be the output of the code?
1,3,5
2,4
1,2,3,4,5
1,3
In Python, what is the purpose of an "elif" statement?
It represents the end of a loop
It is used to define functions
It is short for "else if" and adds additional conditions
Exits the current loop prematurely
Consider the code snippet shown.
What will be the output of the code?
1,4,9
1,2,3,4,5,6,7,8,9
2,4,6
3,6,9
What is the purpose of conditional statements in Python?
To repeat a block of code
To perform different actions based on conditions
To define functions
To print output to the console
What is the output?
more than 7
more than 23
spam
7
What is syntax?
a catch-all for every other situation besides true.
pieces of code that direct the program to run in different ways depending on what else is happening.
a set of rules for how a language is written.
English, Chinese, or Spanish.
Pieces of code that only run "under certain conditions":
conditional statements
control flow statments
syntax
variables
This is a catch-all for every other situation besides the one where the condition is true.
then
do
else
if
Which symbol means "not equal to"?
==
<=
>=
!=
If you want to test more than one condition (chained condition), what do you use after if statement?
elif
else
ifif
else if
Data type that can only be true or false
int
string
boolean
float
Which character must be at the end of the line for if?
:
;
.
{
1. Which of the functions is called when z = 12?
sayHi()
sayHello()
sayGoodbye()
Which of the following is true about if-elif-else statements?
After using if, an elif can be added as an additional test
The bodies of multiple elif’s can run
You can use an elif without an if
Code in an else body runs if all the tests before it were True
What shape will be in front if x = 5?
r
c
s
What shape will be in front if x = 6?
r
c
s
Which two (2) lines of code will print when this function is called?
What is the name of the function?
When defining a function, the definition must occur before it is called.
true
false
What does the following code output?
11, 9
16, 16
None, None
225, 117
Consider the line of code:
Label('Go Team', 200, 100)
What is the Label?
argument
parameter
function name
Which of the following is the correct code to define a function?
def area ( ):
area ( )
def area:
def area ( )
How do you identify the statements that belong to the body of a function?
Indent those statement the same amount underneath the function "def" statement
Add opening and closing curly braces { and } to mark the start and stop of the function body
Add the "def" keyword to the beginning of each statement
Add the same comment (#) to the right of each statement within the body
What character should be placed at the end of the function "def" line, after the parentheses?
Hashtag (#)
Colon(:)
Exclamation (!)
Dash (-)
Which keyword marks a spot in a function where the program flow will go back to the calling code?
break
return
continue
jump
If a function named "mystery" is defined as taking no parameters, how would you call that function from your code?
#mystery
mystery[]
mystery()
mystery
Which of the following best describes where you should define your function in your code?
Near the bottom of the source file, after that function is called by any main program code
Always place functions in a separate source file
Near the top of the source file, before that function is called by any main program code
The location is not important, so place the function wherever you like
Which of the following is NOT a Python rule for naming functions?
Functions names can contain letters, numbers and underscores
Function names must be less than 32 characters
The first character in a function name cannot be a number
Function names are case-sensitive
Which of the following statements correctly defines a function named "haunted" that takes a parameter named "apple"?
haunted(apple)
haunted
def haunted(apple):
apple
. Which of the following definitions for the "haunted" function will correctly set the default value for the "surprise" parameter equal to the number 1?
haunted(fear, surprise) = 1
def haunted(fear, surprise=1):
def haunted(fear, surprise "1")
def haunted[fear, surprise=1]
Which of the following statements will successfully send the value "EEK" back from a function to the calling code?
EEK
return EEK
back EEK
#print(EEK)
How many return statements can you place inside one function body?
As many as needed; each marks a spot where program flow returns to the calling code
You can have one return statement per parameter that is defined by the function "def"
You are limited by the number of body statements, divided by 2
Exactly one
What controls a variable's scope?
The location where it is first initialized within your code
The comment you place to the right of the variable name
The capitalization you select for the letters in your function name
The length of your variable name
Which of the following rules is true about locally scoped variables?
Local variables can hold less data than global variables
Local variables can be seen and accessed from any part of the program code
Local variables will keep their same value over repeated calls to the function
Local variables can only be seen and used from inside a function
