From the course: Programming Foundations: Fundamentals
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Exploring conditional code - Python Tutorial
From the course: Programming Foundations: Fundamentals
Exploring conditional code
- In the real world, we make decisions based on current conditions all of the time. If it's raining, I'll take my umbrella. If I'm sleepy, I'll grab a cup of coffee and so forth. The most common way for a computer to make decisions is by means of an if statement. We've seen an example of an if statement earlier in this course, but let's dive deeper to understand the ins and outs. An if statement has this general structure. It starts with the word if, that's where it gets its name from, then it checks some condition, and if that condition is true, then it will do the work that you've placed inside of it. To visualize this, think of it as a flow chart with only one check, if it's true, then the program will proceed to execute the statements. If not, then it just ignores those statements as if they don't exist. Here's a simple if statement in Python. It starts with the word if, then we have our condition, or boolean…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.