Assembled by Adam Whaley, Original Text: How to Think like a Computer Scientist., Original Text: Problem Solving with Algorithms and Data Structures, Original Text: Python for Everybody - Interactive
Q-4: Which of the following properly expresses the precedence of operators (using parentheses) in the following expression: 10 > y or x + y == 10 and x is not y? Might be best to try on paper first.
Try again! The precedence of the operators is incorrect.
(10 > (y or x) + y == (10 and x) is not y)
Try again! The precedence of the operators is incorrect.
(10 > y or x + y == 10 and x is not y)
Try again! The precedence of the operators is incorrect.
((10 > y) or (((x + y) == 10) and (x is not y)))
Correct! Parentheses should be added in the following order: (x + y), (x is not y), (10 > y), ((x + y) == 10), (((x + y) == 10) and (x is not y)), ((10 > y) or (((x + y) == 10) and (x is not y))).
(((10 > y) or ((x + y) == 10)) and (x is not y))
Try again! The precedence of the operators is incorrect.
Q-5: What would be the outputs for transform_string('green'), transform_string('door'), and transform_string('mountains') in order? (Note: Ignore whitespaces.)