It is best to use a POGIL approach with the following. In POGIL students work in groups on activities and each member has an assigned role. For more information see https://cspogil.org/Home.
If you work in a group, have only one member of the group fill in the answers on this page. You will be able to share your answers with the group at the bottom of the page.
In Python, a comparison (e.g., 100 < 200) will yield a Boolean value of either True or False. Most data types (including int, float, str, list, and tuple) can be compared using the following operators:
Python uses indentation to define the structure of programs. The line indented under the if statement is executed only when number < 0 is True. Likewise, the line indented under the else statement is executed only when number < 0 is False.
Statements that are indented under an if/else statement are executed based on the status of the ifβs condition. Statements indented at the same level as the if/else statement later in the program are always executed. If you indent code incorrectly or inconsistently, a SyntaxError: unexpected indent may be in your future.
Expressions may include Boolean operators to implement basic logic. If all three operators appear in the same expression, Python will evaluate not first, then and, and finally or. If there are multiple of the same operator, they are evaluated from left to right.
Q-14: If two True Boolean expressions are compared using the and operator, what is the resulting Boolean value? What if you compare two False expressions instead?
Q-15: If two True Boolean expressions are compared using the or operator, what is the resulting Boolean value? What if you compare two False expressions instead?
Q-16: If a True and a False Boolean expression are compared using the and operator, what is the resulting Boolean value? What if you use the or operator instead?
Suppose you wanted to print the sum of x and y only when both x and y are positive. Write a block of code to achieve this that uses only one if statement.
Rewrite your code from the previous code block using the not operator. Your answer should yield the same result as before, not the opposite, and still only use one if statement. Hint: youβll need to change the > signs!
Suppose that you instead wanted to print the sum of x and yexcept when both x and y are positive. Write a block of code to achieve this that only uses one if statement.