get started with python coursera week 2 quiz answers
Test your knowledge: Functions
1. A data professional wants to define their own Python function. What keyword should they use at the start of the function block?
- with
- for
- return
- def
2. Modularity is the ability to write code in separate components that work together.
- True
- False
3. Why do data professionals use comments for their Python code? Select all that apply.
- To outline the steps of a process
- To execute code
- To provide helpful explanations
- To document their work for teammates
Test your knowledge: Conditional statements
4. Fill in the blank: Comparators are operators that compare two values and produce _____ values.
- string
- integer
- boolean
- float
5. When comparing two expressions, what logical operator requires both expressions to be true to return a True result?
- with
- not
- or
- and
6. Which of the following is a reserved keyword that sets up a condition in Python?
- if
- as
- else
- with
7. The elif keyword only works when there are exactly two possible conditions in the code.
- True
- False
Weekly challenge 2
8. A data professional wants to define a function to calculate the volume of a box. What code should they begin with?
- def volume_box(length, width, height):
- else volume_box(length, width, height):
- if volume_box(length, width, height):
- return volume_box(length, width, height):
9. Which Python keyword makes a function produce new results and save the results for later use?
- if
- as
- return
- def
10. What are the benefits of using clean code for data work? Select all that apply.
- Enhance teamwork
- Save time and effort
- Eliminate the need for hashtags when commenting
- Reduce errors
11. In Python, what is the process of restructuring code while maintaining its original functionality?
- Refactoring
- Converting
- Branching
- Reprogramming
12. A data professional wants to summarize a function’s behavior and explain its arguments and return values. What should they add to the beginning of the function’s body?
- An algorithm
- A logical operator
- A docstring
- A comparator
13. What is the Python comparator for equal to?
- ==
- <=
- !=
- >=
14. A data professional writes the following code: print(33 > 12 or 9 < 7). What result will Python display when they run the code?
- False
- Not equal
- True
- Equal
15. In Python, when does an if statement execute a piece of code?
- When the condition evaluates to not equal
- When the condition evaluates to false
- When the condition evaluates to equal
- When the condition evaluates to true
16. Fill in the blank: In Python, the _____ statement sets a piece of code to run only when the condition of the if statement is false.
- then
- else
- elif
- if
17. A data professional wants to define a function to calculate the square of a number. What code should they begin with?
- return find_square(n):
- if find_square(n):
- def find_square(n):
- else find_square(n):
18. Fill in the blank: A data professional can use the _____ keyword to make a Python function produce new results and save the results for later use.
- else
- return
- def
- if
19. What is the term for code that is written to be readable and to make its purpose clear?
- Self-documenting
- Branching
- Immutable
- Open source
20. A data professional adds a docstring to the beginning of a function’s body. What is the purpose of the docstring?
- To define the function
- To summarize the function’s behavior and explain its arguments and return values
- To make the function produce new results and save the results for later use
- To run the function and print the results
21. In Python, when does an else statement execute a piece of code?
- When the if statement contains text data
- When the if statement contains a false condition
- When the if statement contains a true condition
- When the if statement contains numeric data
22. A data professional wants to define a function to calculate the area of a rectangle. What code should they begin with?
- else area_rectangle(length, width):
- return area_rectangle(length, width):
- def area_rectangle(length, width):
- if area_rectangle(length, width):
23. A data professional wants to make a Python function produce new results and save the results for later use. What keyword should they use in their code?
- else
- and
- if
- return
24. What are best practices for writing clean code? Select all that apply.
- Modularity
- Redundancy
- Clarity
- Reusability
25. Fill in the blank: Refactoring is used to create _____, which is code that is written in a way that is readable and makes its purpose clear.
- open source code
- immutable code
- self-documenting code
- branching code
26. A data professional writes the following code: print(not 4 == 'Data'). What result will Python display when they run the code?
- Equal
- Not equal
- False
- True