From the course: Python for Students (2019)

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Using if

Using if

- [Instructor] We make decisions everyday. We decide when to get up, what to wear, what to have for breakfast. If it's raining, we might decide to get up a little earlier to give ourselves more time to get to school, and we decide to wear sneakers instead of flip flops so that our feet don't get wet. In this video, I'm going to teach you how to have Python make decisions. You'll be able to ask Python to check if a certain condition is met and perform or not perform an action based on that condition. Looking at this code, we have two variables. One is called numbers, and it contains a list of the numbers one through 10. We also have a variable called numbers greater than five which just contains an empty list. In this program, I want to loop through the numbers one through 10, and if the number is greater than five, I'm going to store it in the numbers greater than five list. Let's do that. To loop through the numbers one through 10, we're going to use a for loop.…

Contents