- VC Healy
- May 24, 2020
- 1 min read
Some more control tools.
if Statement
In the statement there does not need to be any elif or Else statements they are both optional.
There can however be multiple elif statements if required. Just make sure that the code is still readable.
If an Else statement is used then this must be the last statement of the if statement.
>>> x = int(input("Please enter an integer: "))
Please enter an integer: 42
>>> if x < 0:
... x = 0
... print('Negative changed to zero')
... elif x == 0:
... print('Zero')
... elif x == 1:
... print('Single')
... else:
... print('More')
...
More
u