WorksheetsProgramming Sandbox 3
Total questions: 100
Worksheet time: 56mins
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
How would you create a program to display "Hello World!"
print(Hello World!
input("Hello World!")
print("Hello World!")
print(Hello World!)
How would you create a program to display "Hello World!"
print(Hello World!
input("Hello World!")
print("Hello World!")
print(Hello World!)
Which python operator means 'less than or equal to'?
>=
>
<
<=
What will be the output?
name = "Dave"
print (name)
Dave
'Dave'
name
(name)
Which symbol means "not equal to"
%
==
!=
**
What is an example of a boolean?
"Hello!"
56
True/False
46.7
23 == 32
True
False
4 == 4.0
True
False
Error
What is the purpose of a loop in programming?
The purpose of a loop in programming is to repeat a block of code.
The purpose of a loop in programming is to randomly select a block of code.
The purpose of a loop in programming is to skip a block of code.
The purpose of a loop in programming is to execute code only once.
What is the output of the following code?
x = 5
y = 3
print(x + y)
8
2
15
7
What will this symbol do?
\n
Not
New line
Does nothing
A while loop can be used in which of the following situations?
Repeat a set of statements till a condition remains True.
Repeat a set of statements a finite or an infinite number of times.
Iterate through a string, list, and tuple.
All of the above
What is a variable?
a type of graphics
A box(memory location) where you store values
Data type
a type of memory
What symbol is used in python to assign values to a variable?
equals =
plus +
minus -
asterisk *
What will be the output?
name = "Dave"
print (name)
(name)
Dave
name
Nothing
A syntax error means your code has a 'grammar' mistake or you used symbols/operations incorrectly
True
False
Which statement correctly assigns the string "Tanner" to the variable name?
name = print( "Tanner")
input("Tanner")
name= "Tanner"
name = input("Tanner")
What is the output from the following code?
print ("hello world")
hello world
nothing
"HELLO WORLD"
What will be the output?
name = "Dave"
print ("name")
Dave
name
"name"
"Dave"
Kind of loop used when you know the number of times you want it to repeat
list
for
while
if
Loop that runs till the condition is true
list
while
for
if
In Python, the two types of loops are _____ and _______
while
for
list
if
Choose the correct output of the following code.
for i in range(10,15):
print(i)
10
11
12
13
14
15
10
11
12
13
14
11
12
13
14
15
11
12
13
14
What symbol do you use to make a comment in Python?
+
//
$
#
What type of data is the following?: X = "195.67"
Float
String
Boolean
Integer
What type of variable is the following?: Y = False
Float
String
Integer
Boolean
What does the following Python program print?
X = "Hello World!"
Y = "I can code "
Z = " In Python"
print( X + Y + Z)
Hello World! I can code In Python
Hello World!I can code In Python
Hello World! I can codeIn Python
Hello World!I can code In Python
Variables have three things:
Numeric, string, Boolean
Integer, float, string
name, type, value
function, value, name
When you want to print something to the screen you should use
The keyboard to type it
The computer Display
A monitor
a print statement
print("Python " * 3); will print out what
Python 3 Python 3 Python 3
Python Python Python
PythonPythonPython
Python*3 Python*3 Python*3
Which one to the following Python programs will not run?
num = 4
greeting = "Hello"
print(num + greeting)
grade = 98.7
letterGrade = "A+"
print(str(grade) + letterGrade
studentNum =80
print("studentNum")
print("Hello World!")
Which of the following is NOT a program that will produce the following output?
SeasonSeasonSeason
word = "Season" * 3
print(word)
word = "Season" + "Season" + "Season"
print(word)
num = 3
word = "Season" * 3
print(word)
word = "Season"
print(word)
print(word)
print(word)
float, integer, boolean, and string are all examples of what?
Variables
Data Types
Words
Concatenation
The following statement/code snippet is an example of what?
color = blue
All is correct
Variable/variable assignment
Variable declaration
Variable initialization
Which character must be at the end of the line for if?
:
;
.
{
Pieces of code that only run "under certain conditions":
conditional statements
control flow statments
syntax
variables
What is the output?
more than 7
more than 23
spam
7
In what situation it will display the butterfly image?
When i is less than 5
When i is greater than 5
When i is greater and equal to 5
Any situation
Else if (elif) is used in which situation?
If the previous conditions were not true
You can use if statement to replace elif
else is enough for now
Any situation
What is elif in Python?
eliminate if
else if
A person's name
False
What will this output?
Mine is too!
An error
MINE IS TOO!
Nothing
What would be outputted here?
it divides by 7!
it divides by 3.
It divides by 7!
It divides by 3.
What will this program output?
:(
":("
Error
nothing
What will be the output of this code?
x = 14
y = 13
y = x + 3
if x<=y:
print("Hurray")
else:
print("Yay")
Hurray
Yay
14
13
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 be the output of this code?
x = 13
y = 14
if x==y:
print("Hello")
else:
print("Hi")
Hello
Hi
13
14
In Python, what are if-statements used for?
Looping
Indexing
Decision Making
Testing
Look at the following code:
name = "John"
age = 23
What type of data is stored in the variable name?
str
int
float
nothing
Look at the following code:
name = "John"
age = 23
What type of data is stored in the variable age?
str
int
float
nothing
Look at the following code:
name = "John"
age = "23"
What type of data is stored in the variable age?
str
int
float
nothing
If I want to store my height in a variable, which of the following would be a good variable name in best practice?
abcdefg
inches
number
height
If I want to store my name in a variable, which of the following would be a good variable name in best practice?
name
teacher
mister
abcdef
If I want to store multiple names in variables, which of the following would be good variable names in best practice?
a
b
c
name1
name2
name3
Audrey
Ben
John
blah1
blah2
blah3
Look at the following code:
age = "23"
age = int(age)
What does the int() function do to the data in my variable?
does nothing
changes the string to a float
changes the number to a string
changes the string to an integer
Look at the following code:
age = 23
age = float(age)
What does the float() function do to the data inside age?
changes the string to an int
changes the int to a string
adds a decimal point (23.0)
does nothing
What is the output?
more than 7
more than 23
spam
7
What part of an if statement should be indented?
All of it
The statements within it
the first line
the lines within the brackets
Right or Wrong
True or False
==
!=
>
<
What is the result of the code:
team = ("Cowboys")
if team == "Cowboys":
print("Dallas is #1")
Error
Cowboys
Team
Dallas is #1
What will happen when this program is run?
Syntax error
One will be displayed
Zero will be displayed
One then Zero will be displayed
What will happen when this program is run?
Syntax error
Big will be displayed
Small will be displayed
300 will be displayed
if age is less than 20 then
What is the name of the variable in this program?
colour
input
" "
What symbol must you place at the end of an if statement?
)
:
;
}
1==0
True
False
=
;
:
==
