Databricks Certified Data Engineer Associate — Question 99
A data engineer only wants to execute the final block of a Python program if the Python variable day_of_week is equal to 1 and the Python variable review_period is True.
Which of the following control flow statements should the data engineer use to begin this conditionally executed code block?
Answer options
- A. if day_of_week = 1 and review_period:
- B. if day_of_week = 1 and review_period = "True":
- C. if day_of_week = 1 & review_period: = "True":
- D. if day_of_week == 1 and review_period:
Correct answer: D
Explanation
The correct answer is D because it uses the equality operator '==' to compare day_of_week with 1 and checks if review_period is True correctly. Option A incorrectly uses a single '=' for assignment instead of '==', while B mistakenly treats review_period as a string instead of a boolean. Option C has syntax errors with incorrect use of '&' and '='.