Learn Python By Example – if and if else

if and if else

Create a variable with the status of the conflict.

  • 1 if the conflict is active
  • 0 if the conflict is not active
  • unknown if the status of the conflict is unknwon

 

conflict_active = 1

If the conflict is active print a statement

if conflict_active == 1:
    print('The conflict is active.')
The conflict is active.

If the conflict is active print a statement, if not, print a different statement

if conflict_active == 1:
    print('The conflict is active.')
else:
    print('The conflict is not active.')
The conflict is active.

If the conflict is active print a statement, if not, print a different statement, if unknown, state a third statement.

if conflict_active == 1:
    print('The conflict is active.')
elif conflict_active == 'unknown':
    print('The status of the conflict is unknown')
else:
    print('The conflict is not active.')
The conflict is active.