Font size
WorksheetsWeek 7 - User Functions
Total questions: 54
Worksheet time: 27mins
A .................... is a named block of code that is used to perform a task and will return one or more values (called the 'return value’).
Procedure
Argument
Function
Call
Parameter is ......
The variable that information is passed to in a function
The data that is passed to a function
Data is sent back to be used by the main program after a function has been run.
An argument is ......
The variable that information is passed to in a function
The data that is passed to a function
Data is sent back to be used by the main program after a function has been run.
What term is used to describe data passed into/out of a program?
Variable
Loop
Constant
Parameter
What will be the output of this program if the user enters "Han" and then "Solo"?
An error
Nothing
first surname
Han Solo
Variables allow us to:
Name different parts of our programs
Use English words to communicate with Tracy
Store information to use in our programs
Change the words Tracy recognizes
How many parameters can we use in each function?
1
2
3
As many as we need
Which keyword is used for function?*
define
fun
def
function
Which of the following function headers is correct?*
def fun(a = 2, b = 3, c)
def fun(a = 2, b, c = 3)
def fun(a, b = 2, c = 3)
def fun(a, b, c = 3, d)
How is a function declared in Python?*
def function function_name():
declare function function_name():
def function_name():
declare function_name():
Which one of the following is the correct way of calling a function?
function_name()
call function_name()
ret function_name()
function function_name()
a=10
a=20
syntax error
value error
Leo wants to create a function that will roll a dice. Which is the correct function definition header?
def dice roll ():
def diceroll ()
def diceroll ():
def diceroll []:
__________ is the built-in function to know the type of a variable or function.
id()
type()
data_type()
none of the above
times is ________________ type of argument.
default arguments
keyword arguments
positional arguments
arbitrary positional arguments
arbitrary keyword arguments
Do you call or define a function first?
call
define
What is the purpose of a function?
They are reusable pieces of programs.
They are required by the Python
They allow us to compile our program
They make the program larger
What are the two main types of functions?
Custom function
Built-in function & User defined function
User function
System function
Which of the statements below is true about indentation in Python?
Indentation only matters in for loops.
Indentation never matters in Python.
Indentation always matters in Python.
Indentation only matters in functions.
4. The suite of a function always comes after a _______.
;
:
'
#
Which of the following are advantages of using function in program?
It increases readability of program.
It increases reusability.
It makes debugging easier.
All of the above
Function defined to achieve some task as per the programmer’s requirement is called a ______________
user defined function
library function
built in functions
All of the above.
What term is used to describe data passed into/out of a program?
Variable
Loop
Constant
Parameter
The output of the code above is
40
30
syntax error
What is a parameter?
Parameters are the values that are passed into a function.
Parameters are the names of the information that is used in a function.
A parameter is a small section of program
What is an argument?
An argument is a value that is passed into a function.
An argument is a small section of program
An argument is the name of the information that is used in a function.
Name the variable in this code:
name = "Daffy"
print("Hi", name)
Daffy
Hi
Name
How many individual variables are in this code?
name = "Goofy"
age = "21"
holiday = "Disney"
print("Hi", name, "I see you are", age, "would you like to go to" holiday, "?")
1
2
3
4
Variables can be changed
True or False?
True
False
What is the output?
more than 7
more than 23
spam
7
Which symbol means "not equal to"?
==
<=
>=
!=
Which character must be at the end of the line for if?
:
;
.
{
What does the = = symbol mean in Python?
Equal to or shows equality
Not Equal
Code that will be skipped
End of clause
Failure
A named blocks of code that are designed to do one specific job is called as________
Loop
Function
Block
Branching
While defining a function which of the
following symbol is used.
;(semi colon)
.(dot)
$(dollar)
:(colon)
Which of the following is used, if you don’t need to type all the python code for the same task again and again?
Statement
Scope
Control Structure
Function
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
Consider the line of code:
Label('Go Team', 200, 100)
What is the Label?
argument
parameter
function name
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
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 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]
The Four Types of data we are learning about are:
Integers, Decimals, Words, Boolean
Numbers, Fractions, Words, Boolean
Integer, Float, String, Boolean
1, 2, 3, 4
What data type would store the value: True
Boolean
String
Integer
Float
What data value would store the value: -9?
Float
Integer
String
Boolean
What data type would store the value: Oranges
String
Float
Boolean
Integer
What data type would store the value: -0.04?
String
List
Boolean
Float
What is the correct code to ask the user their favorite color?
input("What is your favorite color?")
question("What is your favorite color?")
print("What is your favorite color?")
ask("What is your favorite color?")
What is the difference between an input statement & a print statement?
They are the same code.
input displays answers.
print displays questions.
input displays an output on the console.
print accepts input from a user.
input accepts input from a user.
print displays an output on the console.
G Smasha
on the track
is Dillen's favorite rapper
has Drake call him for advice
Best Rapper Alive
