Any concepts on this page might be on the quiz. The quiz will be on November 7.
Scratch and Programming
The Scratch stage measures 480 pixels wide by 360 pixels tall. Locations on the Scratch stage are referred to by their x and y coordinates. x indicates where it is on the horizontal axis, and y to the position on the vertical axis. The center is x=0 and y=0. X values range from -240 to 240 and Y ranges from -180 to 180.
To move a sprite you can either point it in a specific direction and issue the Move (10) Steps instruction, or you can directly change the x and y position of the sprite, usually within a Repeat loop.
Two methods of orchestrating the actions in a Scratch project across multiple sprites are through timing, using the “Wait (0) secs” block, and through broadcast/receive blocks. Broadcast and Receive are covered in the Donut Calculator assignment.
Using the Wait block:
Using message broadcasting:
In Scratch, when you use the Ask block to ask a question, the answer typed in by your program’s user is temporarily stored in the special Answer variable. When asking more than one question, you must save each answer into its own variable. Otherwise it will be overwritten by the answer to the next question.
A Boolean expression is a logical statement that is either TRUE or FALSE . Boolean expressions can compare data as long as both parts of the expression have the same basic data type, for example both are numbers or both are letters or words. You can test data to see if it is equal to, greater than, or less than other data.
Boolean expressions are used by programmers to make certain instructions happen only some of the time, when the expression is TRUE. Whenever you see an “IF” statement in a program, it is using Boolean expressions to determine what happens next.
If/else blocks also have an “else” section for the script instruction blocks you want to run when the boolean expression is FALSE.
Boolean expressions may be modified by the NOT operator, which makes the Boolean expression the opposite of what it would otherwise be. For example, NOT TRUE is FALSE and NOT FALSE is TRUE.
They can also be combined with the use of the AND and OR operators. With the AND operator, the expressions on both sides of the AND must be true for the overall expression to be true. With the OR operator, if either expression is True then the overall expression is true. For example: (2 < 1) OR (3 > 2) is True because at least one of the expressions, in this case (3 > 2), is true.
There will be several questions where you are shown a fragment of Scratch code and asked a question about what will happen when it runs. When solving these problems, it is often useful to make notes with a row for every iteration or pass through a loop and notes of variable values as of each iteration.
Some of the code samples on the quiz will have bugs or defects you will have to identify. Most of the bugs are cases where instructions in the code will fail to ever run, or where they are out of order such that the program will not behave as intended.
Any time you have the ability to name something in your program, you should give it a name that describes its purpose. Your projects should not have a name of “Untitled”, your sprites should not be “Sprite1″ Sprite2” etc, and your variables should not be named “my variable”. The reason for this is to help you and other programmers make sense of your program. The computer is only one audience for reading your programs: when things go wrong, other humans and you yourself need some clues as to what the progammer’s intention was when writing the progam.
Students will be able to define and apply the following terms:
Iterate, iteration, iterative: To repeat a process, In Scratch, this is achieved through the following blocks: “repeat”, “repeat until”, and “forever.”
Boolean Expression: a comparison which evaluates to True or False. Discussed above in more detail.
Concatenate: To join things together. In Scratch we use the Join block to join some text which does not change together with the current value of a variable. For example: “The answer is 42” where 42 is the value of a variable
String Concatenation: When programming, the word string refers to a sequence of letters or characters. A string could be a word or sentence, or any non-numeric information of more than one letter. String concatenation is the operation where words or sentences are connected to form new and longer longer strings.
Conditional Processing: When your program has instructions that only happen some of the time. The primary example in Scratch is the IF block, and its companion, the If/Else block. These contain a Boolean expression. When the Boolean expression is evaluated and is true, the instructions inside the IF block run.
Fair Use: Under the US Fair Use doctrine, there are cases where it is permissible to use others’ work normally protected by copyright. For our work in the classroom at St. John School, we are using these materials for non-profit educational purposes, which is one of the four acceptable uses of materials normally protected by copyright.
Quiz Preparation, Quiz Schedule, and Retakes
Mr. James is available for questions and content review after school on Wednesdays in the Makerspace (during Robotics) and by appointment.
Students must submit the Request to Retake form and contact Mr. James by email to schedule a retake outside of class hours, and they must show up on time when their retake is scheduled.
Knights and Knaves Bonus Problem
To solve this, you must eliminate the impossible from the limited set of possibilities. You must evaluate a series of Boolean expressions. For each person, if you can eliminate one possibility (knight/knave) then the other MUST be true.
Amy: “We are all knaves” Brad: “Exactly one of us is a knight” Cindy says nothing. Knights always tell the truth and never lie. Knaves always lie and never speak the truth.
Amy is a knave. It is impossible for a knight to say “we are all knaves”, because that would require the knight (the person speaking, Amy) to be a knave, which is impossible. We eliminate the possibility Amy is a knight, therefore she must be a knave. This fact is the bedrock on which the rest of the solution may be built.
Brad is a knight, but his situation is a little bit tricky to evaluate.
Consider the two possibilities: (1) Brad is a knight (2) Brad is a knave. Evaluate each of these possibilities against his statement and what we know about Amy. Eliminate the impossible and you will be left with the truth.
First, his statement “exactly one is a knight” is consistent and possible given what we know about Amy, and it also allows for him being the one and only knight. We cannot eliminate this possibility that Brad is a knight. It is possible this is a trick question and unsolvable, with ambiguity preventing us from being certain in our answer, so we must keep working to see if we can eliminate some possibilities and be left only with the truth.
Let’s consider the second possibility: could Brad be a knave, telling a lie by stating “exactly one of us is a knight”? If he is lying, that means either all three are knights, or two of them are knights. If you are evaluating the possibility that “exactly one is a knight” is a lie, these are the only remaining possibilities to consider: all are knights, or two are knights. Since we know for a fact that Amy is a knave, the scenario where all three are knights is impossible and may be eliminated. Knowing that Amy is a knave allows us to eliminate the possibility that two are knights, because that would require Brad and Cindy to be the two knights: this is impossible because we are considering Brad to be a knave in this possibility. Thus we have eliminated all possibilities under the “Brad is a knave” scenario, rendering it impossible. Having eliminated this, we are left with the only possibility being Brad is a knight.
And finally, determining that Cindy is a knave is trivial given that Brad the knight speaks truth in saying there is exactly one knight and we know it to be Brad. Given this knowledge we can eliminate the possibility that Cindy is a knight and conclude she is a knave.
Question: what changes if Brad leaves out the word “exactly” and just says “one of us is a knight”?
There is no bonus point opportunity on quiz retakes, but I promise next year’s quiz will feature more from the island of knights and knaves! If you enjoy these puzzles, you might also enjoy What is the Name of this Book? (pdf)