Python: Control Flow

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Else Statements

(Else Statements) Can be used to execute code when the conditions of an if statement are not met

Boolean Expressions can either be?

- True - False

Except is short for?

Exception

>>>

The prompt when you run Python in your terminal, which you can then use to evaluate simple expressions

Logical Operators

(Boolean Operators) Compare multiple boolean expressions

Relational Operators

(Comparators) Compare two items and return either True or False

Else If Statements

(Elif Statements) Checks another condition after the previous If Statements conditions aren't met

Conditional Statements

(If Statements) Perform different actions depending on whether a specific Boolean evaluates to true or false - They are handled by If Statements

Logical Operators Symbols

- And - (True) And (True) = True - (True) And (False) = False - (False) And (False) = False - Or - (True) Or (True) = True - (True Or (False) = False - (False) Or (False) = False - Not - Not (True) = False - Not (False) = True

Relational Operators Symbols

- Equals: == - Not Equals: != - Greater than: > - Less than: < - Greater than or equal to: >= - Less than or equal to: <=

Describe the control flow in If, Elif, & Else Statements

- First, the if statement is checked - Then each elif statement is checked from top to bottom - Then finally the else code is executed if none of the previous conditions have been met

Which is a boolean expression?

- Today is a weekday - Friday is the best day of the week

What is the difference between = and == in Python?

= is used when defining variables == is used when comparing values

Shell

A command line interface

Boolean Expression

A statement that can either be True or False

Boolean variable

Any variable that is assigned to the values True or False (Bool types)

Try & Except Statements

The First Statement Try will be executed, then if that exception matches the keyword in Except Statement, then the try statement will terminate and the except statement will execute

Bool types

The computer will sign the Bool abbreviation to any boolean data type (True) (False)

Control Flow (OIE)

The order in which instructions are executed

What can Try & Except Statements be used for?

To build error control into your code

Review This Image For Elif Statements

What would happen if all of the elif statements were simply if statements? If you donated $1000.00, then the first three messages would all print because each if condition had been met.


Kaugnay na mga set ng pag-aaral

Principle of Microeconomics Exam 3 Study Set

View Set

CH: 16 POST- OP NURSING MANAGEMENT SET 2-MED SURG I

View Set

Principles of Macroeconomics Mississippi College (Dr. Bolen) Exam 2 (Chapters 8,9,10,11)

View Set

Interactions between organisms and the environment

View Set

7 - Quantitative Measures and Investment Risks

View Set