From the course: Python for Students

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Using if statements

Using if statements - Python Tutorial

From the course: Python for Students

Using if statements

- [Instructor] We make decisions every day. 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. 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 1 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 1 through 10, and if the number is greater than 5, I'm going to store it in the numbers_greater_than_five list. Let's do that. To loop through the numbers 1 through 10, we're going to use a for loop. We then need to add a conditional statement to check if the number is greater than 5. To do that, we use an if…

Contents