Advanced Python Development Course
Chapter
>
Level
Async/Await
Reading Messages
Objective
Check that the item numbers in the wine cellar are correct using the read() function and tally up leftover stock.
The wine cellar has several crates with wine bottles, these are set to be moved upstairs for distribution. In the storeroom, tables will have memos with orders, adjacent to them there will be crates holding the bottles. You need to verify that the number of bottles in each crate matches that of the memos and supplement any missing items.
First, grab the loose bottles that are in the wine room so you may have them at the ready to supplement any items missing from the orders. There are three (3) types of wine bottles, once collected, create variables for them as follows: empty_bottles , purple_bottles , yellow_bottles and store the number you’ve collected of each in the variables.
Once you claim all the bottles in the field, walk to the light X marks inside the storeroom and face the memos. Use the read() function to read the order information on the memo by triggering a pop up. Similar to the write() function, the read() function is an async function that requires await before the code is written, like this: await player.read().
The memos are color coded by the carpets under them, once you are made aware of the order numbers, walk to the dark X marks in front of the color coded crates and use the speak() function to check the contents of each crate. There are three (3) constants corresponding to each of the crates: green_crate , blue_crate and red_crate.
Check that the contents of each crate matches that of the memo of the corresponding color carpet. If there are missing items in the crates that are outlined in the memo add them to the corresponding crates. Create variables: empty_missing , purple_missing and yellow_missing and add the number of each that is missing to the crate’s contents.
Once the variables are set, use the place() function to add the missing bottles to the crates, for example: player.place(empty_missing). After setting all the items, walk to the gold X mark and write() a tally of all the leftover bottles that didn’t get stored.
A draft of the message will be written in the code editor, set the correct amounts of each of the leftover bottles you didn’t store by subtracting the two variables you created, for example: empty_bottles-empty_missing. Once all remaining items have been tallied you will have completed the level.