From the course: Python Quick Start

Unlock this course with a free trial

Join today to access over 24,800 courses taught by industry experts.

Defining conditional statements

Defining conditional statements - Python Tutorial

From the course: Python Quick Start

Defining conditional statements

Oftentimes when you're programming, you'll need to control the flow of your programs execution and conditional statements can help you with that. A conditional statement instructs the computer to perform specific actions if specific conditions are met. For example, say you wanted to build a program that asks the user whether it's raining and if it is raining, tells the user that they need an umbrella. Your program would look something like this. In this cell, in the first line, I created a variable named "raining" and assigned it the user's answer to the question, "Is it raining?" Yes or no? In the second and third lines, I check if the user responded yes. And if they did, you need an umbrella gets printed out. I'll go ahead and run the cell and I'll act as a user, I'm asked the question, Is it raining? Yes or no? Currently, where I am, it's not raining, so I'll answer "no" and press "Enter." And now if I print out "raining" I get "no," which is exactly what I answered. Now, you know…

Contents