Python Development Course
Chapter
>
Level
Creating Lists
Referencing list items
Objective
Grab eggs basket and check how many eggs you have inside, then place the eggs in their proper containers by referencing their position within a list.
Today’s fresh batch or eggs have been collected and placed in a basket. Grab the basket and check how many eggs you have of each type so you can put them away. There are four types of eggs inside the basket: "white eggs", "dark eggs", "red eggs" and "blue eggs".
First grab the basket set by the containers and walk to the light X mark next to the table. After reaching the light X mark and facing the table, use a while loop to check the eggs you have in the basket.
count = 0 while count < 4: player.speak("I have %d %s in compatment %d" % (basket[count],eggs[count],count) ) count += 1
There are two (2) list constants contained in the basket. One list that holds the names of all four (4) eggs available to you named eggs. And another list named basket that holds how many eggs of each color the basket contains.
The basket has four (4) compartments, counted 0 - 3 , eggs of each color are stored in their own compartment. This also tells you their location and order within the lists which is as follows:
0 = white eggs 1 = dark eggs 2 = red eggs 3 = blue eggs
Walk to the dark X marks next to containers and use the place() function to place the correct type of egg in the right container. Each container has a sign informing you of what color egg is stored there.
You can address each type of egg in your list by identifying where in the list they are located like this: basket[0] .The number in brackets being the location of the value within the list. This method allows you to access a specific value within the list by writing the name of the list along with the index of the value you wish to access.
Walk to all four dark X marks and place the eggs of each corresponding type in their proper location. For example: player.place(basket[0]) being used on the dark X mark with the white eggs sign. Reference the numbered chart above, use it in combination with place() and basket[] on all four dark X marks to complete the level.