Introduction to Python
  • Introduction
  • Preface
  • Background
  • Installing Python
  • Getting Started
  • Basics
    • More Printing
    • Strings
    • Numbers
    • Exercises
    • Comments
  • Variables
    • Operators
    • Type Conversion
    • Exercises
    • A Brief Introduction to Lists
    • Game Exercise
  • Human Input
  • Functions
    • First Functions
    • Why Functions
    • Exercises
  • Indentation
  • Decisions
    • Booleans
    • Logical Operators
    • If Statements
    • Elif and Else Statements
    • Exercises
    • Rock, Paper, Scissors
    • Game Exercise
    • Game Exercise 2
  • Lists
  • Loops
    • For Loops
    • While Loops
  • More Data Structures
    • Tuples
    • Dictionaries
  • Pygame
  • Extra Content
    • Computers and Code
    • More About Python
    • For Loops with Range
    • List Slicing
Powered by GitBook
On this page

Decisions

Decisions, life is full of them. Imagine going to a store to buy a snack. Some chocolate you like costs $7 and there's a slice of lemon cake for $5. If you have money for both of them, you'll buy both. If only have money for one then you'll buy chocolate if you can't afford it. If you can't afford chocolate then you'll buy the lemon cake.

Computers can reason just like that if we want them to. Python uses if-statements to decide whether a block of code should be run or not. To determine if code needs to be run, we check if a condition is true.

PreviousIndentationNextBooleans

Last updated 6 years ago