Python Development Course
Chapter
>
Level
Conditions
Basic if statement
There are times you may wish to add conditions to certain actions you take, this would allow your code to be flexible and perform different actions depending on the situation. For this we use if statements in combination with operators to test certain conditions and perform appropriate actions.
In this first exercise, gather eggs and use == and != operators to check if certain values in a list are the same or different from one another.

Objective
Grab all the eggs in the field and compare them to each other using conditions in an if statement.
Grab all the eggs in the field by walking over them, once you have collected them store them in a list named basket .
basket = ["blue egg", "red egg", "shinny egg", "green egg"]
Once you set up the list, walk to the X marks to compare them to each other and the constant named eggs by setting up conditions in an if statement. The eggs constant has a general value for the eggs you have on hand.
if basket[0] == basket[1]: player.speak("This statement is True!") else: player.speak("This statement is False!")
This code compares the first two items in the list together, the == operator is used to check if the two items being compared are the same. If the they are, the first command is taken, if not the code under the else statement is run instead.
Run this same if statements in the following two X marks but use the following conditions:
if basket[1] != basket[2] and if basket == eggs . The operator != is used to check if the two items being compared are not the same.