Font size
WorksheetsPython Test
Total questions: 100
Worksheet time: 1hrs 8mins
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
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
Print statement
Outputs a message on the screen
Gets data from the user
A decision
A loop controlled by a decision
Input statement
Outputs a message on the screen
Gets data from the user
A decision
A loop controlled by a decision
If else statement
Outputs a message on the screen
Gets data from the user
A decision
A loop controlled by a decision
While statement
Outputs a message on the screen
Gets data from the user
A decision
A loop controlled by a decision
For statement
Outputs a message on the screen
Gets data from the user
A decision
A loop controlled by a counter
Def statement
Outputs a message on the screen
Gets data from the user
A decision
Create a procedure or function
How is Python similar to Scratch?
They are both text-based languages.
They are not similar.
They are both number based languages.
print("Hello world!")
Which character must be at the end of the line for if?
:
;
.
{
What is the output?
more than 7
more than 23
spam
7
What will this output?
Mine is too!
An error
MINE IS TOO!
Nothing
What will be the output of this code?
x = 13
y = 14
if x==y:
print("Hello")
else:
print("Hi")
Hello
Hi
13
14
What will be the output of this code?
x = 13
y = 14
if x!=y:
print("Hello")
else:
print("Hi")
Hello
Hi
14
13
What will display at the end of the program running?
You can ride the carousel!
Nothing will display
Sorry! Not tall enough!
There will be an error.
What will display at the end of the program running?
You can ride the carousel!
Nothing will display
You cannot ride the carousel!
There will be an error.
How do you define(assign) variables?
var="String"
func==Hello
var : 123
word= Hello
What is the end after if statements?
if
Elif
Else
While
Which of the following is a correctly-formatted comment?
*Comment
"Comment"
#comment
(comment)
A line of text that Python won't try to run as code
Integer
Comment
Strings
Input
What will be the value of last_jedi after the following code is run?
["kylo", "rey", "finn", "luke"]
["kylo", "rey", "finn"]
3
4
What will this code print?
6
1
pants
"pants": 6
What is the correct syntax to write a for loop to iterate through the list grades?
for variable:
for variable in grades
variable in grades:
for variable in grades:
What will be the value of colors after the following code is run?
["light blue", "pink"]
["light blue", "yellow", "pink"]
["pink", "yellow"]
["light blue", "yellow"]
What will be the value of n after the following code is run?
[6]
[1, 8, 6, 4, 2]
[8, 6, 4, 2, 1]
[8, 4, 2]
What will be the value of n after the following code is run?
[2, 2, 3, 5]
[1, 2, 4, 5]
[1, 3, 3, 5]
[2, 3, 4, 6]
What will be the value of n after the following code is run?
[1, 3, 5]
[3]
[1, 5, 7]
[1, 3, 7]
How many lines will the code below print to the console?
4
5
2
3
Which of the following is the correct way to create an empty list?
empty_list = []
empty_list = {}
empty_list = [0]
empty_list = None
What is the output of the following code?
"Moonlight"
"Casey Affleck"
"Emma Stone"
"Zootopia"
("Best Picture", "Moonlight")
("Best Actor", "Casey Affleck")
("Best Actress", "Emma Stone")
("Animated Feature", "Zootopia")
"Best Picture"
"Best Actor"
"Best Actress"
"Animated Feature"
"Best Picture" : "Moonlight"
"Best Actor": "Casey Affleck"
"Best Actress": "Emma Stone"
"Animated Feature": "Zootopia"
What will the following code output?
"soda"
KeyError
["veggie burger", "salad", "soda"]
["hamburger", "fries", "soda"]
What would be the output of the following code snippet?
a_dict = {'color': 'blue', 'fruit': 'apple', 'pet': 'dog'}
d_items = a_dict.items()
print(d_items)
('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')
dict_items([('color'), ('fruit'), ('pet')])
[('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')]
dict_items([('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')])
Which of the following are true of Python dictionaries:
Dictionaries can be nested to any depth.
Dictionaries are accessed by key.
All the keys in a dictionary must be of the same type.
Dictionaries are mutable.
A dictionary can contain any object type except another dictionary.
A Python dictionary stores ...
value - key pairs
key - value pairs
quiz = {"Do you help out at home? ":"yes",
"Do you beleive in Santa? ":"yes"}
What is a list in python?
A collection of variables
A collection of items assigned to a single variable
A statement that cant be changed
A Christmas list
What is the output from this code?
ell
llo
ello,
Hello
str1="101"
x=int(str1)
z=x+400
print(z)
101400
x400
501
none of above
index of a string begins with
1
0
a
-1
cheer = "Go Eagles!"
print cheer[1:4]
What will the output be from the following code?
print("Hello world!" * 2)
TypeError
Hello world world!
Hello world!Hello world!
Hello world! * 2
What will the output be from the following code?
print("3+4")
7
34
3+4
SyntaxError
Which of these is a list?
fruit = ["apples", "oranges", "bananas"]
fruit = "apples", "oranges", "bananas"
fruit = {"apples", "oranges", "bananas"}
fruit = ("apples", "oranges", "bananas")
Each item in a list has an "address" or index. The first index in a Python list is what?
1
0
a
A
["a", "b", "c"]
["a"]
["a", "b"]
[]
a
b
c
Error
1
2
3
4
["o"]
["a", "b", "c", "o"]
o
["c", "o"]
["a", "c"]
["b"]
["a", "b", "c"]
["a", "b", "c", "b"]
A (a) is a data structure that can hold more than 1 value at a time. It is a collection or ordered series of elements of the same type.
We can create an array that is able to store any data type.
True
False
Arrays are ...................data types?
built-in
user defined
computer
analysis
The total number of elements in the array is called...............
Length
memory
index
subscript
What is a Boolean?
True or False statement
Numerical Operator
A cube that is used for a soup base.
A Ghost on a tree
What does the following comparison operator “!=” represent in Python programming?
Equal to
Assignment
Allocation
Not equal to.
What is the result of the following code?
print(10 == 9)
True
False
What is the result of the following code?
print(10 != 9)
True
False
In Python the multiplication sign is...
*
%
.
'
What is an expression in Python
something i feel strongly about
a math problem
a saying with a meaning behind it
syntax
in Pyton the exponent or power sign is
^
**
>
"
Syntax is...
an error
a coding language that explains Python what to do
rules we follow in building sentences
ways to express yourself
What is the truth value for the compound Boolean statement?
5 == 2 + 3 or 7 > 8
True
False
No Value
In the provided code, what is the final output?
"Fred"
15
25
35
In the provided code, which lines of code will be skipped by the computer when the program is run?
7
7, 10, 11
10, 11
7, 10
Which code means not equal to?
==
<=
>
!=
What is the name of the function?
Consider the line of code:
Label('Go Team', 200, 100)
What is the Label?
argument
parameter
function name
What can be used to store information and values so that it can be used later?
Graphic
Variable
Output
What is the word (command) used to display numbers and text on the screen?
show
output
command
What will be the output?
name = 'Dave'
print (name)
name
Dave
error
What is a input?
To plug in something.
A function that allows us to ask the user to enter some data.
Data displayed on a screen.
A function
