Teacher's Guide

Chapter 4 / Level 3: Setting up a question

Teaching Objective:

  • Student understands how the question() function works and it’s purpose
  • Learns how to set up the custom functions and specific syntax in relation to the question() function
  • Understands the various use cases and examples of the question() function and it’s flexibility

Guide

In this exercise we’re going to be working with await/async functions, specifically the question() function. This function allows us to pose a question which displays as a pop up message with Yes and No buttons for answers. In order to effectively use the function you need to create a custom function that processes what action to take in accordance with the answer the function returns.

In this level we are going to use this in order to either collect() or place() variable ingredients, those being: "water" , "ice" , "meat" and "potato". The goal of this level is to set and prep kitchen materials and ingredients for later consumption. The question() setup functions are provided as follows.

async def dispencer():

  answer = await player.question(
    "Would you like ice instead of water?")

  if answer:
    player.collect("ice")
  else:
    player.collect("water")

async def oven():

  answer = await player.question(
    "Would you like bake instead of grill?")

  if answer:
    player.place("potato")
  else:
    player.place("meat")

Walk to gold X mark on the right side room and use the dispencer() custom question function twice in order to collect both "ice" and "water" .

await dispencer()

await dispencer()

Walk to the dark X mark in front of freezer and use place() function to deposit "ice". Walk to light X mark in front of sack and collect "potato".

player.place("ice")

player.collect("potato")

Walk to the dark X mark next to the pot and use place() function in order to deposit "water" . Walk to the light X mark by the freezer and use the collect() function to gather "meat".

player.place("water")

.....

player.collect("meat")

Walk to gold X marks located in the left room and use the oven() custom question function. For the question on the right oven bake the "potato" , for the question on the left oven grill the "meat" in order to complete the level.

await oven() # bake potato

.....

await oven() # grill meat

Map overview and path

Map overview and path

Code Solution

import player

async def dispencer():

  answer = await player.question(
    "Would you like ice instead of water?")
  
  if answer:
    player.collect("ice")
  else:
    player.collect("water")
    

async def oven():

  answer = await player.question(
    "Would you like to bake instead of grill?")
  
  if answer:
    player.place("potato")
  else:
    player.place("meat") 
    
player.move_forward(4)
player.turn_left()
player.move_forward(4)
player.turn_left()
player.move_forward()
await dispencer()
await dispencer()
player.turn_right()
player.move_forward()
player.turn_left()
player.place("ice")
player.turn_right()
player.turn_right()
player.move_forward(4)
player.collect("potato")
player.turn_right()
player.move_forward(2)
player.turn_right()
player.move_forward(2)
player.turn_right()
player.place("water")
player.turn_left()
player.move_forward(2)
player.collect("meat")
player.turn_left()
player.turn_left()
player.move_forward()
player.turn_right()
player.move_forward(6)
player.turn_right()
player.move_forward()
await oven()
player.turn_left()
player.move_forward()
player.turn_right()
await oven()

Chapter 4 / Level 3: Setting up a question | Teacher's Guide