Certified Data Engineer Associate Exam QuestionsBrowse all questions from this exam

Certified Data Engineer Associate Exam - Question 22


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?

Show Answer
Correct Answer: CD

To execute a code block conditionally based on the values of variables in Python, you need to use the equality comparison operator (==) for checking equality, not the assignment operator (=). Additionally, when dealing with Boolean values, you should use the variable directly without comparing it to the string 'True'. So, the correct statement is 'if day_of_week == 1 and review_period:', which checks if day_of_week is equal to 1 and if review_period is True.

Discussion

15 comments
Sign in to comment
4be8126Option: D
Apr 5, 2023

The correct control flow statement to begin the conditionally executed code block would be D. if day_of_week == 1 and review_period:. This statement will check if the variable day_of_week is equal to 1 and if the variable review_period evaluates to a truthy value. The use of the double equal sign (==) in the comparison of day_of_week is important, as a single equal sign (=) would be used to assign a value to the variable instead of checking its value. The use of a single ampersand (&) instead of the keyword and is not valid syntax in Python. The use of quotes around True in options B and C will result in a string comparison, which will not evaluate to True even if the value of review_period is True.

surrabhi_4Option: D
Apr 10, 2023

option D

prasiosoOption: D
May 13, 2023

in python value comparison is done by double equal signs (==). in case of boolean values that are TRUE these may be omitted. Quotes around True would result in string comparison and here we are comparing to a bool value.

MircuzOption: D
Mar 4, 2024

C fits if you're looking for a string == 'True', in this case you are using a boolean so D

XiltroXOption: C
Apr 5, 2023

I believe the right answer is C

lgkofficialwork
Jun 20, 2023

It's not C. Conditional check of "True" is treated as a string and not Boolean. Hence D is the right answer

MajjjjOption: D
May 4, 2023

The data engineer should use option D: if day_of_week == 1 and review_period:. This statement checks if the variable day_of_week is equal to 1 and if the variable review_period is True. It uses the double equal sign (==) to compare the values of the variables, and does not use quotes around the keyword True, which is a boolean value.

Bob123456Option: D
May 10, 2023

Answer is 'D' day_of_week=1 review_period = True 1) if day_of_week == 1 and review_period: print("yes") output: Above code block's output is yes 2) if day_of_week == 1 and review_period == "True": print("yes") output: There is no output for above code block

AtnafuOption: D
Jul 8, 2023

D if day_of_week == 1 and review_period:

[Removed]Option: D
Aug 29, 2023

Answer is D

vctrhugoOption: D
Sep 3, 2023

D. if day_of_week == 1 and review_period: The correct control flow statement to begin the conditionally executed code block is option D. In Python, the == operator is used for equality comparison, and and is used for logical "and" operations. So, this statement checks if day_of_week is equal to 1 and review_period is True (a boolean value), which is the correct way to express the conditions you mentioned.

VijayKulaOption: D
Oct 16, 2023

review_period == "true" is different from review_period == true

awofalusOption: D
Nov 7, 2023

D is correct

GarynOption: D
Dec 30, 2023

D. if day_of_week == 1 and review_period: - In Python, the equality comparison operator is ==, not =. == is used to check if two values are equal. - The logical operator "and" is used to combine two conditions, ensuring that both conditions (day_of_week == 1 and review_period) are true for the subsequent code block to execute. - day_of_week == 1 checks if the variable day_of_week is equal to the integer value 1. - review_period is already assumed to be a Boolean variable since it is stated to be True (without quotes) in the question. Therefore, it should not be compared to a string "True". Therefore, option D correctly represents the condition for executing the final block of the Python program based on the given conditions.

SerGreyOption: D
Jan 4, 2024

D is correct

3fbc31bOption: D
Jul 8, 2024

You need the == to use the "equals" operation. A single "=" is an assignment operation.