conditionals chapter 3 Flashcards

1
Q

What is boolean operation?

A

A boolean expression is an expression that is either true or false. The following examples use the operator ==, which compares two operands and produces True if they are equal and False otherwise:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what is a logical operator?

A

There are three logical operators: and, or, and not. The semantics (meaning) of these operators is similar to their meaning in English. For example,

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what is a conditional excution?

A

Conditional statements give us this ability. The simplest form is the if statement:
if x > 0 :
print(‘x is positive’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what is another alternative excution?

A

A second form of the if statement is alternative execution, in which there are two possibilities and the condition determines which one gets executed. The syntax looks like this:

if x%2 == 0 :
print(‘x is even’)
else :
print(‘x is odd’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what are chained conditionals?

A

Sometimes there are more than two possibilities and we need more than two branches. One way to express a computation like that is a chained conditional:

Sometimes there are more than two possibilities and we need more than two branches. One way to express a computation like that is a chained conditional:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what is a nested conditional?

A

One conditional can also be nested within another. We could have written the three-branch example like this:

if x == y:
print(‘x and y are equal’)
else:
if x < y:
print(‘x is less than y’)
else:
print(‘x is greater than y’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How is Try and Except display?

A

The idea of try and except is that you know that some sequence of instruction(s) may have a problem and you want to add some statements to be executed if an error occurs. These extra statements (the except block) are ignored if there is no error.
ex:
inp = input(‘Enter Fahrenheit Temperature:’)
try:
fahr = float(inp)
cel = (fahr - 32.0) * 5.0 / 9.0
print(cel)
except:
print(‘Please enter a number’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Debugging

A

The most useful parts are usually:

What kind of error it was, and

Where it occurred.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what are the comparisson operators?

A

comparison operator
One of the operators that compares its operands: ==, !=, >, <, >=, and <=.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what is a compund statement

A

compound statement
A statement that consists of a header and a body. The header ends with a colon (:). The body is indented relative to the header.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly