Teacher's Guide

Chapter 4 / Level 4: Async review

Teaching Objective:

  • Student practices Async functions and becomes better acquainted with them
  • Learns more use cases and applications for Async functions
  • Better understands syntax for Async function and is able to further optimize using them

Guide

In this exercise we will be reviewing Async functions and using in conjunction with each other in order to complete a process. For this level we will be documenting material production for wine in order to have it bottled.

First ensure berries can be soaked or collected by setting up the soaking_pot() as a question() function.

async def soaking_pot():
  answer = await player.question("Collect berries instead of soaking them?")
  if answer:
    player.collect("wine berries")
  else:
    player.place("berries")

Walk to the dark X mark with no carpet that’s in front of a bar with a piece of paper. Use the read() function and create a variable named quota and pass on the value you read from the document to it.

await player.read()

quota = 1000

Walk to light X marks and use read() function to find out how much product is finished and stored. Take the values found in the crates in a variable named wine_berries,

await player.read()

wine_berries = 825

Walk to the gold X mark in the lower right side of the field and collect() "berries" from the sacks.

player.collect("berries")

Walk to the dark X marks at the bottom of the field, use the soaking_pot() , question() function to determine if you should collect or place items. Collect wine berries on the green and yellow carpeted X marks and place in berries so they may be soaked in the pot for the rest of the X marks.

await soaking_pot()

........

await soaking_pot()

Walk to the left side gold X mark and face the crates. Use the place() function in order to store the wine berries you previously collected. Add 100 points to the variable created to represent the items you added.

player.place("wine berries")

wine_berries+=100

Walk to the dark X marks on the top of the field. On the red carpeted one, use the write() function to chart down the amount of product you have already processed by using the wine_berries variable.

On the orange carpeted dark X mark, subtract quota and wine_berries variables while using the write() function in order to chart down remaining product and complete the level.

player.write("There are %d pounds of product finished" % (wine_berries))

...............

player.write("There are %d pounds of product Remaining" % (quota-wine_berries))

Map overview and path

Map overview and path

Code Solution

import player

async def soaking_pot():
  answer = await player.question("Collect berries instead of soaking them?")
  if answer:
    player.collect("wine berries")
  else:
    player.place("berries")

player.move_forward(2)
player.turn_right()
player.move_forward(5)
await player.read()

quota = 1000

player.turn_left()
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()

wine_berries = 825

player.turn_right()
player.move_forward()
player.turn_right()
player.move_forward(2)
player.turn_right()

player.collect("berries")

player.turn_right()
player.turn_right()
player.move_forward()
player.turn_right()
player.move_forward(2)

await soaking_pot()

player.turn_right()
player.move_forward(2)
player.turn_left()

await soaking_pot()

player.turn_right()
player.move_forward()
player.turn_left()

await soaking_pot()

player.turn_right()
player.move_forward(2)
player.turn_left()

await soaking_pot()

player.turn_right()
player.turn_right()
player.move_forward(6)
player.turn_right()
player.move_forward()

player.place("wine berries")

wine_berries+=100

player.turn_left()
player.move_forward(2)
player.write("There are %d pounds of product finished" % (wine_berries))

player.turn_right()
player.move_forward(3)
player.turn_left()
player.write("There are %d pounds of product Remaining" % (quota-wine_berries))
Chapter 4 / Level 4: Async review | Teacher's Guide