In Python you can define conditional statements, known as if-statements.
A block of code is executed if certain conditions are met.
Python Programming Bootcamp: Go from zero to hero
Consider this application, it executes either the first or second code depending on the value of x.
If you set x to be larger than 10, it will execute the second code block. We use indentation (4 spaces) to define the blocks.
A little game:
A variable may not always be defined by the user, consider this little game:
age = 24
A word on conditional operators
a = 12
This can quickly become difficult to read, consider combining 4 or 6 conditions. Luckily Python has a solution for this, we can combine conditions using the and keyword.
guess = 24
Sometimes you may want to use the or operator.
If you are new to Python programming, I highly recommend this book.