Exercise 4: If statements

A program sometimes may have to make choices.  These choices can execute different code depending on certain condition. In Python the if statement is used for conditional execution.

The if statement may be combined with certain operator such as equality (==), greater than (>=), smaller than (<=) and not equal (!=). Conditions may be combined using the keywords or and and.

Related: Complete Python Bootcamp: Go from zero to hero in Python


In the example below we show the use of if-statements.
Copy the program below and run it.

Visual example of if statement:
if statement

Study drills

Do these exercises:

Once completed continue with the next exercise.



Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">