4.3 From pseudocode to Python functions - Quiz¶
Section 4.3 Quiz: From pseudocode to Python functions
-
What keyword is used to define a function in Python?
- function
- def { data-correct }
- define
- func
-
What does the
returnstatement do in a function?- Prints a value to the screen
- Sends a value back to the code that called the function { data-correct }
- Ends the program
- Starts a new function
-
What will this
mystery(5)?function return when called as- 10
- 5
- None { data-correct }
- An error occurs
-
Which of the following is the correct way to call a
calculate_areawith parameterslength=10andwidth=5?function named- calculate_area(10, 5) { data-correct }
- calculate_area[10, 5]
- def calculate_area(10, 5)
- return calculate_area(10, 5)
-
What is the Single Responsibility Principle for functions?
- Functions should only use single-character variable names
- Functions should only be called once in a program
- Functions should do one specific task well { data-correct }
- Functions should only have one parameter
-
What is a parameter in a function?
- The value the function returns
- Information passed to the function when it’s called { data-correct }
- The function’s name
- The first line of the function body
-
What is wrong with this function definition?
- The function name should be capitalized
- Default parameters must come after non-default parameters { data-correct }
- The return statement should use + instead of f-strings
- Nothing is wrong with it
-
What will be the output of this code?
- 12
- 14
- 24 { data-correct }
- 10
-
Which of the following best describes a “pure function”?
- A function that only uses built-in Python functions
- A function with no syntax errors
- A function that always produces the same output for the same inputs and has no side effects { data-correct }
- A function that doesn’t use any parameters
-
What should you include in every function to explain what it does?
- A comment at the end of the function
- A docstring immediately after the function definition { data-correct }
- A print statement showing the function name
- A global variable with the function description