From the course: Python Quick Start
Unlock this course with a free trial
Join today to access over 24,500 courses taught by industry experts.
Working with if statements - Python Tutorial
From the course: Python Quick Start
Working with if statements
Conditional statements help you control the flow of your programs execution. A conditional statement instructs the computer to perform certain actions if certain conditions are met. The simplest conditional statement is called an if statement. An if statement instructs the computer to perform a specific action or set of actions If a specific condition is satisfied. For example, say you asked the user for an integer between -10 and 10 and if the number they enter is less than 5, a message is displayed to the user. You would do something like this. I'll call input, which is a built-in Python function and I'll pass in the following prompt. Choose an integer between -10 and 10 and enter it here. So the user will be prompted to enter an integer between -10 and 10. Now, I want to store the user's response. So I can create a variable named 'n' and assign it to the user's response. Note that the function input always returns the user's response to the prompt as a string, so 'n' is a string…
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.