Coding for KidsCoding for Kids
Creative LevelsChallengesTeacher's Guide
Vote for features
Advanced Python Development Course
Chapter
>
Level

Async/Await
Setting up a question

Objective

Collect various kitchen materials and prep for cooking by setting up “questions”.

There are various kitchen and food materials than need to be set and prepped for later use and consumption. To facilitate this you can set up a question() , this is an async function similar to write() but instead of displaying a static message, you can display a question with “Yes” and “No” options.

To set up the question() function you must also set up a custom function in order to handle conditions. This function must have async written at the start to establish it as an async function. Inside, the question() function is stored inside a variable and the function has await written in front like the the other async functions. As an argument, the question() function has a string with the question you’re gonna ask.

async def question_function(): answer = await player.question("Question you would like to ask") if answer: # Actions to take if answer is Yes else: # Actions to take if answer is No

Inside the function you’ll have an if statement that determine what action to take if the answer is true or false. The question custom functions will be set up in the code editor and will allow you to collect and/or place multiple items from a single source.

The items in question that need to be prepped in the kitchen are: "water" , "ice" , "meat" and "potato". These items need to be collected and placed in different areas in the kitchen. The "ice" needs to be placed inside a freezer, the "water" needs to be put inside the pot, the "meat" and the "potato" both need to be placed inside different ovens.

First walk to the gold X mark on the right room and use the custom function await dispencer() that is outlined in the code editor. Face the ice box and use the function two (2) times. It will ask a question and you must answer Yes to collect() "ice" and No in order to collect() "water".

Once you have collected both those items, walk to the dark X mark next to you, in front of the freezer, and use the place() function to deposit the "ice" inside the freezer. Like this: player.place("ice") . Then walk down to the light X mark in front of a sack and use the collect() function to grab a "potato" like this: player.collect("potato") .

Afterwards, walk to the dark X mark next to the center pot and place() the "water" you had collected, like this: player.place("water") . Once done walk up to the light X mark above that, in front of the refrigerator and collect "meat", like this: player.collect("meat") .

Now that you have collected both the "meat" and the "potato" , walk to the two (2) gold X marks on the left room and use the await oven() custom function that’s written in the editor. For the question, on the right oven, you must choose the answer to bake the "potato" and for the left oven you must choose the answer to grill the "meat" in order to complete the level.

Code book