What will 'print(both)' output?
False
How should range tests like a ≤ x < b be written in Python?
As (a <= x) and (x < b).
1/141
p.9
Logical Operators

What will 'print(both)' output?

False

p.15
Common Mistakes in Logical Operations

How should range tests like a ≤ x < b be written in Python?

As (a <= x) and (x < b).

p.5
Boolean Data Type

What data type represents true or false values in Python?

bool

p.17
Logical Operators

What logical operator has higher precedence in the expression provided?

The 'and' operator has higher precedence than 'or'.

p.25
Indentation in Python

Why is indentation important in Python?

It determines the block of code that belongs to a conditional statement.

p.28
Common Mistakes in Logical Operations

What type of input does the program ask from the user?

A number.

p.23
If/Else Statement

What does the program print when y equals 0?

It prints 'Y is zero.'

p.26
Indentation in Python

What is the recommended maximum line length in Python code?

Less than 80 characters.

p.3
Branching and Conditionals

Why do we use branching in programming?

To execute statements only if certain criteria are satisfied.

p.12
Control Flow

What Python function is used to get user input in the program?

input()

p.8
Logical Operators

What is the result of 'a or b' when both a and b are False?

False.

p.20
If-Statement

What does an if-statement consist of?

A test expression and a body.

p.10
Boolean Data Type

What is the result type of a logical operator?

Boolean (bool).

p.19
Control Flow

What does a <condition> evaluate to in control flow?

True or False.

p.11
Logical Operators

What output is produced if the mark is between 70 and 75?

You get a B+.

p.5
If-Statement

What should the test expression (condition) evaluate to?

Either True or False.

p.8
Boolean Data Type

What is the result of 'not a' when a is True?

False.

p.6
Comparison Operations

What types of data can be used to form a test expression?

int, float, string.

p.16
Control Flow

What are the relational operators listed?

<, <=, >, >=, ==, !=.

p.12
If/Else Statement

What is the output if the year is not a leap year?

The year isn't a leap year!

p.8
Logical Operators

What is the result of 'a and b' when either a or b is False?

False.

p.16
Logical Operators

Which logical operator represents OR?

or.

p.6
Control Flow

What is a test expression?

An expression formed by comparison or logical operations.

p.3
Common Mistakes in Logical Operations

What will happen if y is zero in the provided program?

A run-time error will occur.

p.3
If/Else Statement

What is the purpose of checking if y is zero in the program?

To prevent a run-time error during division.

p.7
Comparison Operations

What does 'i < j' evaluate?

Evaluates to True if i is less than j, otherwise False.

p.10
Control Flow

What is a test expression in the context of logical operators?

An expression that can consist of sub-expressions combined using logical operators.

p.2
Control Flow

What does control flow refer to in programming?

Control flow determines the order in which individual statements, instructions, or function calls are executed.

p.2
Boolean Data Type

What is the boolean data type?

The boolean data type represents two values: True and False.

p.15
Common Mistakes in Logical Operations

What is a common mistake when using assignment and comparison operators?

Mixing '=' with '=='.

p.17
Control Flow

What is the correct way to add parentheses to show the precedence in the expression '17 x + 3 >= 9 or z != x * 2 and not(y / 2 < 3)'?

(17 x + 3 >= 9) or (z != (x * 2) and not(y / 2 < 3))

p.27
Indentation in Python

What does indentation refer to in Python?

The spaces at the beginning of a code line.

p.17
Logical Operators

What does the 'not' operator do in the expression?

It negates the result of the expression that follows it.

p.26
Indentation in Python

Why might template files use fewer spaces for indentation compared to Python files?

Template files tend to have more levels of nesting.

p.12
If/Else Statement

What is the output if the year is a leap year?

The year is a leap year!

p.22
If-Statement

What type of input is expected for x and y in the code?

Integer input.

p.27
Indentation in Python

What constitutes a block of code in Python?

Code written at the same indentation level.

p.25
If/Else Statement

What will be printed if x is a positive odd number?

It is a positive odd number.

p.4
Comparison Operations

What are relational operators?

Operators used to compare values, such as ==, !=, <, >, <=, and >=.

p.16
Control Flow

What is the operator for exponentiation?

**.

p.7
Boolean Data Type

What do comparison operations evaluate to?

Boolean (bool), either True or False.

p.7
Comparison Operations

What is the result of the comparison 'i > j'?

Evaluates to True if i is greater than j, otherwise False.

p.24
If/Else Statement

How does an if/else statement represent alternatives?

It represents the idea more naturally and clearly.

p.24
If/Else Statement

What does the 'if' part of an if/else statement do?

Executes the body if the test expression is true.

p.18
Logical Operators

Which operator has lower precedence than 'and' but higher than 'or'?

>= and !=

p.14
Short-Circuit Evaluation

What will happen if 'count' is zero in the second program?

It will give an error.

p.11
Logical Operators

How can the code be simplified using logical operators?

By combining conditions into a single if statement.

p.26
Indentation in Python

How many spaces are recommended for each indentation level in Python?

Four spaces.

p.12
Control Flow

What does the program prompt the user to input?

The year to be checked.

p.27
Indentation in Python

How does Python use indentation?

To indicate a block of code.

p.13
Short-Circuit Evaluation

In the expression (expr1 and expr2), when is expr2 not evaluated?

When expr1 is false, making the whole expression false.

p.13
Short-Circuit Evaluation

How does short-circuit evaluation simplify program code?

By avoiding unnecessary evaluations of sub-expressions.

p.25
If/Else Statement

What will be printed if x is a positive even number?

It is a positive even number.

p.21
Indentation in Python

What must be consistent in the body of an if-statement?

The indentation must be the same.

p.29
Control Flow

What type of numbers does the challenge extension require as input?

6 floating point numbers corresponding to the (x, y) coordinates of the triangle's corners.

p.10
If/Else Statement

What grade will you receive if your exam score is at least 70 and less than 75?

B+.

p.18
Logical Operators

What operator has the highest precedence in the given expression?

not

p.18
Boolean Data Type

In the expression, what does 'not(y / 2 < 3)' evaluate?

It evaluates to the negation of whether y divided by 2 is less than 3.

p.2
Indentation in Python

Why is indentation important in Python?

Indentation is used to define the scope of loops, functions, and conditionals in Python.

p.19
Branching and Conditionals

What happens if the <condition> is True?

Expressions in that block are evaluated.

p.16
Control Flow

What can you use to force the evaluation order in expressions?

Parentheses.

p.16
Control Flow

Which operators have the highest precedence?

Logical NOT.

p.5
Control Flow

What is an expression in programming?

An expression has a value and a type.

p.22
If-Statement

What is calculated when y is not equal to 0 in the provided code?

The value of x divided by y.

p.4
If/Else Statement

What happens if the condition in a branching statement is false?

The statement is skipped.

p.3
Control Flow

What is the main characteristic of sequential programs?

All statements are executed one-by-one.

p.4
Comparison Operations

What does the test expression 'y != 0' check?

Whether y is not equal to 0.

p.20
If-Statement

When is the body of an if-statement executed?

Only if the test expression evaluates to true.

p.9
Boolean Data Type

What is the value of 'derive' in the example?

True

p.29
If/Else Statement

What output is given when the lengths 3, 4, and 5 are input?

This is a triangle!

p.24
If/Else Statement

What is the basic syntax of an if/else statement?

if test_expression_TE: body_to_be_executed_if_TE_is_true else: body_to_be_executed_if_TE_is_false.

p.29
Control Flow

What is the purpose of the program described in Exercise 2?

To check if three given lengths can form a triangle.

p.24
If/Else Statement

What does the 'else' part of an if/else statement do?

Executes the body if the test expression is false.

p.28
If-Statement

What should the program do when the user inputs an even number?

Print 'Even'.

p.22
If-Statement

Can the body of an if-statement be empty?

No, it can't be empty.

p.14
Short-Circuit Evaluation

What is the significance of short-circuit evaluation in the first program?

It prevents division by zero by checking 'count != 0' first.

p.4
If-Statement

What is the purpose of a test expression in control flow?

To determine whether a statement should be executed based on a condition.

p.5
Comparison Operations

What does the variable 'isZero' represent in the expression 'isZero = (y == 0)'?

It checks if 'y' is equal to 0.

p.23
If/Else Statement

How many if-statement bodies are executed regardless of the value of y?

Only one if-statement body is executed.

p.20
If-Statement

What is the purpose of an if-statement?

To perform branching based on a test expression.

p.10
Logical Operators

What are the three main logical operators mentioned?

and (AND), or (OR), and not (NOT).

p.4
Control Flow

What is the output of the code if y equals 0?

The code will not execute the division statement.

p.29
If/Else Statement

What is the condition to check if three lengths can form a triangle?

a + b > c, b + c > a, and c + a > b.

p.20
If-Statement

What is the syntax structure of an if-statement in Python?

if test_expression: followed by the body.

p.2
Branching and Conditionals

What is branching in programming?

Branching allows the program to take different paths based on conditions.

p.7
Comparison Operations

What does 'i == j' test for?

Tests for equality; True if i is the same as j.

p.18
Control Flow

What is the role of parentheses in logical expressions?

They clarify the order of operations and precedence.

p.22
If-Statement

What does the pass statement indicate in an if-statement?

That no actions should be done.

p.25
Common Mistakes in Logical Operations

What is a potential problem in the provided code examples?

Dangling 'else' problem.

p.22
If-Statement

What happens if y is equal to 0 in the provided code?

The pass statement is executed, and no action is taken.

p.17
Comparison Operations

In the expression 'y / 2 < 3', what is being compared?

The result of 'y / 2' is being compared to 3.

p.25
If/Else Statement

What does the second if statement check in the provided code?

If x is even (x % 2 == 0).

p.16
Logical Operators

Which logical operator represents AND?

and.

p.13
Short-Circuit Evaluation

What should be considered when using short-circuit evaluation?

The order of the sub-expressions.

p.12
Logical Operators

What logical operators are used in the leap year condition?

and, or

p.21
Indentation in Python

What does indentation refer to in Python?

The spaces at the beginning of a code line.

p.10
If/Else Statement

What will you receive if you fail in the quiz, exam, or do not hand in assignments?

A warning letter.

p.11
Logical Operators

What does the condition 'mark >= 70 and mark < 75' check?

It checks if the mark is between 70 and 75.

p.14
Short-Circuit Evaluation

What is the condition checked in both programs?

Whether 'scores / count' is less than 60 and 'count' is not zero.

p.12
If/Else Statement

What is the condition for a year to be a leap year?

A leap year is divisible by 4, but not divisible by 100, unless it is divisible by 400.

p.23
If/Else Statement

What happens when y is not equal to 0 in the provided code?

The program calculates and prints the value of x divided by y.

p.8
Boolean Data Type

What is the result of 'not a' when a is False?

True.

p.8
Logical Operators

What is the result of 'a and b' when both a and b are True?

True.

p.6
If-Statement

In the expression 'if (a and b)', what are 'a' and 'b'?

Variable names with Boolean values.

p.26
Indentation in Python

What should be avoided regarding blank lines in Python programs?

Excessive use of blank lines.

p.4
If/Else Statement

What will the code 'val = x / y' execute?

It will execute if y is not equal to 0.

p.20
Indentation in Python

How does Python identify the body of an if-statement?

By relying on indentation (the number of white spaces at the beginning of a line).

p.7
Comparison Operations

What does 'i >= j' check?

Checks if i is greater than or equal to j.

p.9
Boolean Data Type

What is the value of 'drink' in the example?

False

p.9
Logical Operators

What does 'both = derive and drink' evaluate to?

False

p.2
Short-Circuit Evaluation

What is short-circuit evaluation?

Short-circuit evaluation is a programming technique where the second argument is evaluated only if the first argument does not suffice to determine the value of the expression.

p.11
Logical Operators

What is the purpose of using logical operators in programming?

To simplify some program code.

p.28
If-Statement

What should the program do when the user inputs an odd number?

Print 'Odd'.

p.23
If/Else Statement

What is the purpose of an if/else statement?

To allow the program to choose only one of two alternatives.

p.16
Control Flow

What is the order of arithmetic operators in terms of precedence?

*, /, %, //, +, −.

p.13
Short-Circuit Evaluation

What is short-circuit evaluation?

Sub-expressions in a test expression are not evaluated if the value of the entire expression is already known.

p.6
Logical Operators

What logical operations can be used to form a test expression?

Logical operations on bools.

p.5
Boolean Data Type

What are the only two possible values of the bool type?

True or False.

p.21
If-Statement

What is a block statement in an if-statement?

A block of code that executes multiple actions when the test expression is true.

p.23
If/Else Statement

What type of input does the program expect for x and y?

Integer input.

p.9
Comparison Operations

What is the value of 'pset_time' in the example?

15

p.21
Indentation in Python

How does Python indicate a block of code?

By using indentation.

p.8
Logical Operators

What is the result of 'a or b' when either a or b is True?

True.

p.10
Boolean Data Type

What type of values do logical operators take as input?

Boolean values (bool).

p.29
If/Else Statement

What output is given when the lengths 3, 4, and 15 are input?

This is NOT a triangle!

p.14
Short-Circuit Evaluation

Are the two provided programs the same?

No, they are not the same.

p.26
Indentation in Python

What is the purpose of indentation in Python?

To determine when one line of code is connected to the line above it.

p.28
Control Flow

What is the main condition being checked in the program?

Whether the number is even or odd.

p.27
Indentation in Python

What is a block of code in Python?

A composed set of several statements to be executed when a certain condition is met.

p.25
If-Statement

What does the first if statement check in the provided code?

If x is greater than 0.

p.21
If-Statement

What is composed of several statements in an if-statement?

A block of code.

p.3
If-Statement

What is an example of a condition that can cause a run-time error?

If the variable y is zero.

p.9
Comparison Operations

What is the value of 'sleep_time' in the example?

8

p.9
Comparison Operations

What does 'print(sleep_time > pset_time)' evaluate to?

False

p.24
If/Else Statement

What are the two alternatives in an if/else statement?

The input number y is either equal to zero (y == 0 is true) or not equal to zero (y != 0 is true).

p.7
Comparison Operations

What does 'i <= j' signify?

Checks if i is less than or equal to j.

p.18
Control Flow

What is the correct way to add parentheses to the expression '18 x + 3 >= 9 or z != x * 2 and not(y / 2 < 3)'?

(((x + 3) >= 9) or ((z != (x * 2)) and (not((y / 2) < 3))))

p.7
Comparison Operations

What does 'i != j' indicate?

Indicates inequality; True if i is not the same as j.

p.2
If/Else Statement

What is the purpose of an if/else statement?

An if/else statement allows the program to execute one block of code if the condition is True and another block if it is False.

p.2
Logical Operators

What are logical operators used for?

Logical operators are used to combine conditional statements.

p.2
If-Statement

What is an if-statement?

An if-statement executes a block of code if its condition evaluates to True.

Study Smarter, Not Harder
Study Smarter, Not Harder