¿Qué es un Predicado?

Brian wants to add a discussion of domain and range to this part of the course. --MF, 12/16/18
This page has been restructured yet again.

Need to check solution files (including numbering and note on problem 2). --MF, 8/8/19

En este laboratorio, tú vas a desarrollar herramientas que ayudarán a resolver una sopa de letras mediante la búsqeuda de palabras que cumplan con ciertas características.

En esta página, tú vas a revisar predicados y construir algunos que podrás utilizar en otros proyectos.

AAP-2.H.1

As you know, predicates are reporter blocks (functions) that always report a Boolean value (they report only the values true or false). In Snap!, predicates are represented by hexagonal blocks. They compute the condition used by conditionals (such as if, if else, or repeat until) to decide when to do something. Predicates ask a question such as "Is the random number 3?" or "Is this sprite touching the sprite called 'Leader'?"

Every if else block has two scripts inside of it, exactly one of which will be run depending on the value that the predicate reports. Then the computer continues with whatever comes after the if else block.
if (pick random (1) to (4)) = (3) {
    report (join (who) (', who') (does what) ( ) (who) (,))                                                                                          
} else {
    report (who)
} when green flag clicked:
repeat until (touching (Leader)?)
{
    point towards (Leader)
    move (1) steps
}

  1. "U2L3-Predicates"Create a new project called U2L3-Predicates
  2. In Unit 1 Lab 5, you made a script to get the sprite to follow the mouse.
    This image has been updated.

    The solutions file here and for 1.5 needs to be checked and/or edited. --MF, 8/8/19

    go to (mouse-pointer)
    AAP-2.E part a
    Now use one or more of the following relational operators to create a script that lets you use your mouse to write on the stage in two colors depending on the mouse's position on the stage.
    less than, equal to, and greater than predicate blocks
AAP-2.E.2
You may see these five relational operators:
=, >, <, ≥, ≤
as well as a sixth:
, which means "not-equal" and reports false if the two inputs are equal and otherwise reports true (if they are not equal). When you write the () not equal () block, it will work like this:
(3) not equal (4) reporting true (3) not equal (3) reporting false

These six relational operators all report a Boolean value (true or false).

  1. Why is this image blurry? Was it blown up? Can we rebuild it? --MF, 8/8/19
    draggable box checked Make the sprite draw only if the mouse button is down, so that you can draw disconnected shapes. You'll need to uncheck the "draggable" box above the scripting area (shown right) before you try this (so that Snap! doesn't think you are trying to drag the sprite when you click).
    You'll probably want to use the mouse down? predicate block block, which you can find in the Sensing palette.
    bicolor printed hello
: Selection
Selection: AAP-2.G.1; sequencing, selection, iteration: AAP-2.A.4

Selection means deciding (selecting) which part of an algorithm to run based on whether a condition is true or false.

Every algorithm can be constructed using sequencing (following steps in order), selection (deciding), and iteration (repeating).