HAKATEMIA
06Python Programming

Conditional sentences

Easy10MIN

What are conditionals?

Let's say we have a game that ends when a player's HP drops to zero or below. Then we need to check the value of the variable player1_hp and if it is zero or below, we go to the "game over" section in the code. For example, like this:

PY
1player1_hp = 50
2
3if player1_hp <= 0:
4  print("Game over")

The program works as follows:

  • Define a variable player1_hp and assign it the value 50.
  • Checking if the value of player1_hp is less than or equal to (<=) 0.
  • If yes, print "Game over".

So IF SOMETHING then** DO SOMETHING**. Here are two important things about Python: Indentation and Blocks.

1 / 7
Hakatemia Pro

Learn to hack — start here

Hundreds of interactive courses, virtual labs and CTF challenges in your browser. Start a free trial — no card required.