If Statements and Logic Operators

Lecture Overview

Topics Covered:

  1. If/Else Statements - Making decisions in code
  2. Logical Operators - Combining conditions with and, or, not
  3. Comparison Operators - Testing relationships between values
  4. Equality vs Identity - Understanding == vs is
  5. Floating Point Comparison - Why floats are tricky
  6. Nested Conditionals - Complex decision trees
  7. Input Validation - Checking user input before processing

Part 1: Basic If/Else Statements

Why Do We Need Conditionals?

Programs need to make decisions based on different situations:

Conditionals allow your program to execute different code based on whether conditions are true or false.

Basic If Statement Syntax