How to program our robot to make a decision in an unforeseen situation Pro Preview

The "if" logical operator allows us to predict the conditions which the robot could wind up in, but what do we do if the conditions aren't met? Luckily. we have a solution to this problem.

To access the full video please subscribe to


  • #1628
  • 11 Jun 2020

 The "else" acts as an "Otherwise" expression. This operator can be written right after the "if" operator and will only execute its code if the "if" condition is not met.

Here's how your code should look when using this command:

if condition:
    (code for met condition)
    (code for UNmet condition)
(code that will always be executed either way)

⚠️ Notice the colon after the "else" command. It's common to forget to place it in the beginning and the students wonder why their program does not work!

The "else" operator does not require a condition, which makes it useful for planning for unforseen situations.

Courses and lessons with this Tutorial

This Tutorial is used in the following courses and lessons

Image for Python with LEGO Mindstorms EV3 - Level 2
  • 39
  • 19:58
  • 93
Image for Lesson 2 - Grabber control panel
  • 6
  • 6
  • 7
  • 3d_rotation 2