Skip to content

Step by Step Guide to Building a Conditional (if) Statement

sleepinghungry edited this page Mar 7, 2017 · 3 revisions

Step 1: Use the if keyword

if

Step 2: Include a variable

if variable_name

Step 3: Include an operator

Operators include less than (<), greater than (>), equal to (==), not equal to (!=), less than or equal to (<=), and greater than or equal to (>=)

if variable_name < 

Step 4: Include a 2nd value (either another variable or a literal constant (number or string))

if variable_name < 5

Step 5: Include a colon

if variable_name < 5:

Step 6: Press enter to go to the 2nd line

if variable_name < 5:
|

Step 7: Press tab to indent the 2nd line

if variable_name < 5:
  |

Step 8: Write the code that should be executed if the above condition were true:

if guess1 < 5:  
  print("Too low!  Enter another guess.")

BWX Game Engine pages

Python Pages

Step By Step Guides

Building Conditionals

Lectures

Explaining Conditionals

Assignments

I Am Thinking of a Number...

Clone this wiki locally