Branching Part 1 Flashcards

1
Q

The if statement (2)

What it evaluates and the two paths

A

-If condition is evaluated to True, the code inside the body of if is executed.
- If condition is evaluated to False, the code inside the body of if is skipped.

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

The if…else statement (3)

the two consitions/paths+ when we use it

A

**If the condition evaluates to True,
**the code inside if is executed the code inside else is skipped

**If the condition evaluates to False,
the code inside else is executed
the code inside if is skipped
*

used to execute a block of code among two alternatives.

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

if…elif…else (5)

The paths and when do we use it?

A

If condition1 evaluates to true, code block 1 is executed.
If condition1 evaluates to false, then condition2 is evaluated.
If condition2 is true, code block 2 is executed.
If condition2 is false, code block 3 is executed.

if we need to make a choice between more than two alternatives, then we use the if…elif…else statement.

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

Write a program that caculates the area of a triangle

A

length = int(input(“Enter the length: “))
width = int(input(“Enter the width: “))
area = length * width
print(“Area: “, area)

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

When is branching used?

A

When alternative courses of action are possible and each action may produce a different result

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

Boolean expressions

A

Memory location that only stores a true or false value

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

Branches are

+eg

A

questions with answers that are either true or false
eg. Is it true that the variable num is positive?

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

Branching structure for ‘if’ cases

its reactions

A

Reacts differently only for true cases

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

Branching structure for “if-else” cases

its reaction

A

reacts differently for the true or false cases

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

Branching structure for “if-elif-else” cases

A

Multiple cases possible but only one case can apply, if one case is true then its false that the other cases apply.

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

body of a branch (2)

what it is+ formatting

A
  • a block of prgram instructions that will execute when a Boolean expression evaluates to/works out to true
  • Specified with indenting in python
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

If you dont follow style convention then it is

A

a syntax error

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

Operator/ Operation

A

Action being performed
*The sign (ex: +)

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

Operand

A

The item or items on which the operation is being performed
The number it is operating on

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

Why is indenting manadartory in python?

A

To determine which statements are part of a body

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

How is a body with multiple instructions shown?

A

All the statements have to be indented
Indent everything that executes

17
Q

You should not use _____ for indenting

A

tabs

18
Q

When comparing operands, make sure they are

ex

A

the same tupe or at least comparable. Ex integer and float comparision is okay, Integer and string is not

19
Q

write me a short program with branching that error checks

A
20
Q

Difference between If and If-Else case

A

Unlike If, If-Else also reacts if the condition is not true (false) executing the body of the false statement which is not present in if statements.

21
Q

logical AND

A

applies when call conditions must be met (Everything is true)

22
Q

Logical OR

A

At least one condition must be met. If at least one is true, the result is true.

23
Q

Logical NOT

A

The everyday usage of logical NOT negates a statement

24
Q

Order of operation for complex logical expressions

A
  1. Brackets (inner first)
  2. Negation
  3. AND
  4. OR