Question
QUESTION 1 Python functions must always include parameters, which are defined at the first line that creates the function. True False QUESTION 2 Functions are
QUESTION 1
Python functions must always include parameters, which are defined at the first line that creates the function.
True
False
QUESTION 2
Functions are blocks of code that perform specific tasks. However, it is possible to include one function inside another function to perform more complicated tasks.
True
False
QUESTION 3
Function parameters usually reference variables that are created outside the function definition.
True
False
QUESTION 4
Variables created inside a function can be referenced outside the function, ONLY if the variable is created using the keyword, "global".
True
False
QUESTION 5
The following will create a user-defined function, my_function, without any errors. Select ALL that apply:
A. | def my_function(): print('Hello, world!')
| |
B. | def my_function(1st_param, 2nd_param): print('Hello, world!')
| |
C. | def my_function(param_1=1, param_2): print('Hello, world!')
| |
D. | def my_function(param_1): print('Hello, world!')
|
QUESTION 6
One of the most important aspects of functions is their ability to perform discrete units of work and produce values that can be stored in variables. Which of the following keywords is often the last line of a function and will allow data to pass from within the function to a variable outside the function?
A. | yield
| |
B. | result
| |
C. | break
| |
D. | return
|
QUESTION 7
You would like to create a function that calculates the sum of two numbers. Your function is called sum_of_numbers. Choose an option to fill in the blank below to complete this function:
def sum_of_numbers(a=0, b=0):
c = [BLANK]
return c
A. | a + b
| |
B. | a.add(b)
| |
C. | c + a + b
| |
D. | a
|
QUESTION 8
You create a function my_function, that takes one numeric argument, my_num, and returns a numeric result. You would like to use your function with the numeric value 9.3, and store the result into a variable, my_result. Which single line of code would accomplish this?
A. | my_result(my_function(9.3))
| |
B. | my_function(9.3)
| |
C. | my_result = my_function(my_num)
| |
D. | my_result = my_function(my_num=9.3)
|
QUESTION 9
If you want to generate a sequence of results with a function, the following keyword is often used within the function instead of return to produce results.
A. | generate
| |
B. | produce
| |
C. | yield
| |
D. | output
|
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started