Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Cyber Battle Game
Game elements
Main Game Loop
7. Step 5 – the first version of the main game loop
Final game


Good! Let's focus on putting our game into motion. We need to create the main game loop. Inside the loop, we'll play all the game rounds. The main loop will also be responsible for checking if the game has already ended.

Both robots start with two lives. The game lasts until either

  1. a robot has no lives left, or
  2. 10 rounds have passed.


  1. Create a dictionary named lives_left. It should have two keys, 'A' and 'B'. Both keys should have the value of 2 initially.
  2. Create an integer variable named rounds_left that is equal to 10.
  3. Create the main game while loop with the following logic: while both robots have more than 0 lives and there are more than 0 rounds left, invoke the play_round() function. Once a round has been played, decrease the value of rounds_left in the while loop by 1.
  4. Robots can't lose lives yet, so after the whole loop has finished, print:
    *** Draw! ***

Stuck? Here's a hint!

Your while loop should look like this:

while lives_left['A'] > 0 and lives_left['B'] > 0 and rounds_left > 0:

Remember to decrease the value of rounds_left inside the while loop. Print *** Draw! *** outside the while loop.