Advanced Python Development Course
Chapter
>
Level
Async/Await
Async review
Objective
Document wine bottle production using Async functions by checking quota and finishing up soaking wine berries.
Wine bottle production needs to be met in order to ensure the cellar can produce enough bottles to be stocked. In order to accomplish this wine berries need to be soaked to ensure everything is processed for fermentation and turned into wine.
First walk to the dark X mark with no carpet in front of a paper, this note contains information on the product quota that needs to be produced as well as notes on what berries have been soaked. Use the read() function in order to check the quota and make note of what the wine berry values are and store them in a variable named quota.
Once you know what is required, walk to the light X marks and face the crates to check how much product is ready for processing. Use the read() function on both to verify the contents of the items that are ready. Create a variable named wine_berries and add together the quantities you read in both X marks.
The amount of product finished is not going to be enough to meet quota, walk to the gold X mark on the lower right hand side and face the sacks. Use the collect() function to grab berries from the sacks and proceed to move to the dark X marks over carpets.
There are four (4) pots soaking berries for use in wine, in the document read it shows which pots are ready collect and which pots need berries to be soaked. Use the question() function to check if you would like to collect soaked wine berries or soak berries in the pot. On the green and yellow carpets with dark X marks you need to collect berries and on the purple and blue carpets with dark X marks berries need to be placed.
The question() function necessary to acquire the product is written in the code editor and is named soaking_pot() :
async def soaking_pot():
answer = await player.question("Collect berries instead of soaking them?")
if answer:
player.collect("wine berries")
else:
player.place("berries")
Once the wine berries have been collected walk to the gold X mark on the left hand side next to berry barrels and use the place() function to add in the "wine berries" you collected. On the variable you created wine_berries, add 100 pounds of product, that is 50 for each of the product you previously collected. This is done like this: wine_berries+=100
Move to the dark X marks with red and orange carpets, on the red carpet X mark use the write() function and add the amount of wine_berries you have available so far like this: player.write("There are %d pounds of product finished" % (wine_berries))
On the orange carpet X mark use the write() function to write down product that has yet to be finished. In order to complete the level, subtract quota with wine_berries while writing to determine the remaining items, like this: player.write("There are %d pounds of product Remaining" % (quota-wine_berries))