Week-4-1
Overview of If-Else Branches
If-Else statements enable conditional branching in programming, altering execution flow.
Flowchart Explanation
Flowcharts visually depict programming logic, exemplified by a Hotel Rate Discount Program where
Initial rate: $155; if user age > 65, rate decreases to $135.
Calculating Absolute Values
Absolute value reflects distance from zero:
Positive stays the same (|5| = 5); negative becomes positive (|-10| = 10).
Steps: Input number, check if < 0, convert if true, output.
If-Else Structure
Determines outcomes based on conditions, e.g., insurance payments based on age.
Python Implementation
Translates flowcharts: if condition true, execute; else, execute alternative.
Uses
==
for equality checks.
Multi Branch & Logical Operators
elif
handles multiple conditions; use logical operators (AND, OR, NOT) for combining conditions.
Summary of Boolean Logic
Boolean variables are true/false; evaluated conditions yield boolean results.