Python: if _ _ _ _: elif: _ _ _ _ else: _ _ _ _ The syntax for the alternative action instruction is:
It is very useful bit of code as it allows the computer to take alternative actions depending on conditions. Note the colons - miss them out and you will have an error! The computer chooses which block of actions to execute in this way.
If you want to have more than one alternative you use elif - contracted version of 'else if' Multiple Alternative ActionThe syntax for the multiple alternative action instruction is:
Note that the order in which you write the conditions is important, because the computer checks them from top to bottom and executes only one block, for the first condition that is true. The else block has no condition, so it's a 'catch all' in case no condition is true. This means you have to be very careful to put condition checks in such an order that should the first one not apply it will then go to the next one - not jump directly to 'else'. |
|