Skip to main content

Occupancy Data Analysis

Challenge: A detective monitors a small hotel with 8 rooms. He records the occupancy status of each room for 2 days on the Encoded Message Playground. The 8 colorful rectangles located in the first grid column from bottom to top represent the occupancy status of rooms 1-8 respectively on the first day, while the 8 colorful rectangles located in the second grid column represent the occupancy status of the 8 rooms on the second day in the same order. Each of these rectangles will either be green to indicate the room is occupied or blue to indicate the room is vacant. The object of the activity is to code the VR Robot to record each day’s occupancy information in a list by using the Down Eye Sensor to detect the color of the rectangles located in the first and second grid columns. And create an algorithm to figure out how many rooms were occupied on both the first day and the second day

  • Select the Encoded Message Playground.
  • Choose Puzzle A.
  • Declare two lists to store the occupancy status of the 8 rooms for the first day and the second day.
  • Declare an index variable to represent the item’s position within the list, and set the initial values to 1. 
  • Declare a variable to count and store the number of rooms occupied on both days, and set the initial values to 0.
  • Code the VR Robot to record the occupancy status of the 8 rooms for the first day in the list.
    • Move the robot forward to a rectangle in the first grid column and code the robot to detect the color of the rectangle by using the Down Eye Sensor. 
    • Use the index variable to retrieve an item in the list. Update the item value to “1” if the rectangle is green, and update the item value to “0” if the rectangle is blue.
    • Increase the index variable by 1 to point to the next item’s position in the list.
    • Use a loop to repeat the above steps for a set number of times to record the occupancy status of each room in a list.
  • Code the VR Robot to drive to the second grid column and record the occupancy status of the 8 rooms for the second day in a list.
  • Code the VR Robot to determine how many rooms were occupied on both days.
    • Use the index variable to retrieve a room’s occupancy status of the first day and the second day from the lists respectively. 
    • If the room was occupied on both days, increase the count variable value by 1.
    • Increase the index variable by 1 to point to the next item’s position in the list.
    • Use a loop to repeat the above steps for a set number of times to determine how many rooms were occupied on both days.
  • Monitor the list value and the variable values in the Monitor Console.
  • Use the [print] block to print the number of rooms occupied on both days to the Print Console. 

Helpful Hints

  • Use the replace item block from the Variables category to update an item in a list to a new value. Replace Item Block
    • Matching Python command:Replace Item Python