Teacher's Guide
Chapter 4 / Level 2: Reading Messages
Teaching Objective:
- Student learns what Async/Await functions are and how they’re executed
- Learns the syntax and how to use the write() function
- Understands the use cases and applications of async functions
Guide
In this exercise we will be learning about await/async functions, in particular the write() function. This function allows you to write an message and have it displayed as a pop up. This level’s objective is to label the unmarked crates using the write() function and tally the number of items in each crate.
Walk to light X marks by the crates with colored carpets and use the speak() function to identify the contents of each crate. Use the built in constants : green_crate , blue_crate , red_crate , and orange_crate with the function at the colored carpet designated by the name of the constant.
Once you find out what type of produce is inside the crate use the write() function to label the sign. There will be four (4) different types of produce that can be labeled :"potato" , "onion" , "corn" and "carrot" .
player.speak(green_crate)
await player.write("potato")
# Do the same with red, blue and orange crates
Finally, walk to the gold X mark and add together all constants inside a list named all_crates . Follow this up by using the write() function with the list in order to complete the level.
all_crates = [ green_crate , blue_crate , red_crate , orange_crate ]
await player.write(all_crates)
Map overview and path

Code Solution
import player
player.move_forward()
player.turn_right()
player.move_forward(9)
player.turn_right()
player.move_forward(5)
player.turn_right()
player.move_forward(4)
player.turn_right()
player.move_forward()
player.turn_left()
player.move_forward(5)
empty_bottles = 6
purple_bottles = 8
yellow_bottles = 4
player.turn_left()
player.move_forward(2)
player.turn_left()
await player.read()
player.turn_right()
player.move_forward()
player.turn_left()
await player.read()
player.turn_right()
player.move_forward()
player.turn_left()
await player.read()
player.turn_right()
player.turn_right()
player.move_forward(2)
player.turn_right()
player.move_forward(4)
player.turn_left()
player.speak(red_crate)
purple_missing = 5
player.place(purple_missing)
player.turn_left()
player.move_forward(2)
player.turn_right()
player.speak(green_crate)
yellow_missing = 4
player.place(yellow_missing)
player.turn_left()
player.move_forward(2)
player.turn_right()
player.speak(blue_crate)
empty_missing = 3
player.place(empty_missing)
player.turn_left()
player.move_forward()
player.turn_left()
player.move_forward()
player.turn_right()
await player.write(
("Empty Spares: %d, Purple Spares: %d, Yellow Spares: %d" %
(empty_bottles-empty_missing,
purple_bottles-purple_missing,
yellow_bottles-yellow_missing)))