Boolean Values
Swipe to show menu
Before going further, you will explore something new about Python.
Ninja's Surroundings
To help the Ninja navigate the map, you can look at the cells around it. The following methods let the Ninja check what is nearby:
object_up()checks the cell above the Ninja;object_down()checks below;object_left()checks to the left;object_right()checks to the right.
Each method returns a string describing the object in that cell: "wall", "sushi", or "empty".
String Comparisons
In Python, you can compare strings using:
==checks if two strings are the same;!=checks if two strings are different.
The result of these comparisons is a boolean value.
Boolean Values
In Python, a boolean is a type of value that can be one of two things: True or False.
Since functions like object_up() return strings you can check what the Ninja sees and turn that information into something your code can use:
Is there sushi to the right? β True or False:
ninja.object_right() == "sushi"
Is there a wall to the left? β True or False:
ninja.object_left() == "wall"
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat