<snapdata remixID="11861985"><project name="U2L1-NumberGuessing_SOLUTION" app="Snap! 7, https://snap.berkeley.edu" version="2"><notes></notes><thumbnail>data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKAAAAB4CAYAAAB1ovlvAAAAAXNSR0IArs4c6QAAAzlJREFUeF7t10FKY2EQhdFfUXDiFtyPGxB0oAbcidvJJrIeceIkBAevwVkPlOZy6QI5GaeqyHkfPHK2bdu2fAgMCZwJcEje2S8BAQphVECAo/yOC1ADowICHOV3XIAaGBUQ4Ci/4wLUwKiAAEf5HRegBkYFBDjK77gANTAqIMBRfscFqIFRAQGO8jsuQA2MCghwlN9xAWpgVECAo/yOC1ADowICHOV3XIAaGBUQ4Ci/4wLUwKiAAEf5HRegBkYFBDjK77gANTAqIMBRfscFqIFRAQGO8jsuQA2MCghwlN9xAWpgVECAo/yOC1ADowICHOV3XIAaGBUQ4Ci/4wLUwKiAAEf5HRegBkYFBDjK77gANTAqIMBRfscFqIFRAQGO8jsuQA2MCghwlN9xAWpgVECAo/yOC1ADowICHOV3XIAaGBUQ4Ci/4wLUwKiAAL/h3+/36/39fd3e3q6bm5vRh/Sbjwvwm6f78fGxXl5e1ufn53p7e1v39/fr4uJiPT09raurq9/cxH/9bQL8gftwOKzX19d1fX3917eOx+N6fn5e27Z9hemTCwgwCPB0Oq3Hx8d1fn6+7u7ucn2TS4D/+Ap+eHj4egXvdrt1eXkpnZKAAP0JKaWUrRFg5maqJCDAEqQ1mYAAMzdTJQEBliCtyQQEmLmZKgkIsARpTSYgwMzNVElAgCVIazIBAWZupkoCAixBWpMJCDBzM1USEGAJ0ppMQICZm6mSgABLkNZkAgLM3EyVBARYgrQmExBg5maqJCDAEqQ1mYAAMzdTJQEBliCtyQQEmLmZKgkIsARpTSYgwMzNVElAgCVIazIBAWZupkoCAixBWpMJCDBzM1USEGAJ0ppMQICZm6mSgABLkNZkAgLM3EyVBARYgrQmExBg5maqJCDAEqQ1mYAAMzdTJQEBliCtyQQEmLmZKgkIsARpTSYgwMzNVElAgCVIazIBAWZupkoCAixBWpMJCDBzM1USEGAJ0ppMQICZm6mSgABLkNZkAgLM3EyVBARYgrQmExBg5maqJCDAEqQ1mYAAMzdTJQEBliCtyQQEmLmZKgkIsARpTSYgwMzNVElAgCVIazIBAWZupkoCfwBN/Be3THjJawAAAABJRU5ErkJggg==</thumbnail><scenes select="1"><scene name="U2L1-NumberGuessing_SOLUTION"><notes></notes><hidden></hidden><headers></headers><code></code><blocks><block-definition s="Number guessing game" type="command" category="other"><header></header><code></code><translations></translations><inputs></inputs><script><block s="doDeclareVariables"><list><l>secret number</l></list><comment w="90" collapsed="true">page 1, ex. 3</comment></block><block s="doSetVar"><l>secret number</l><block s="reportRandom"><l>1</l><l>10</l></block><comment w="53.33333333333334" collapsed="true">1.4</comment></block><block s="doAsk"><l>Guess my number (between 1 and 10).</l><comment w="53.33333333333334" collapsed="true">2.1</comment></block><block s="doUntil"><block s="reportEquals"><block s="getLastAnswer"></block><block var="secret number"/></block><script><block s="doAsk"><l>Nope!  Try again.</l></block></script></block><block s="doSayFor"><l>Congratulations!  You win!</l><l>2</l><comment w="53.33333333333334" collapsed="true">2.2</comment></block></script><scripts><comment x="15.33333333333333" y="212.13333333333333" w="321.3333333333333" collapsed="false">Using two ASK blocks, one before and one inside the loop, is one way to avoid the bug described on page 3, with the advantage that a different text can be used when re-asking to make it clear that the player is still guessing the same secret number, not a new one.&#xD;&#xD;Another solution would be to put ANSWER into another script variable, whose initial value should be something that isn&apos;t a number between 1 and 10.  (Snap! actually initializes variables to 0, but it&apos;s good style not to depend on that, if it actually affects the program logic.) </comment><script x="22.999999999999996" y="356.1333333333334"><block s="doDeclareVariables"><list><l>secret number</l><l>player&apos;s guess</l></list></block><block s="doSetVar"><l>secret number</l><block s="reportRandom"><l>1</l><l>10</l></block></block><block s="doSetVar"><l>player&apos;s guess</l><l>0</l></block><block s="doUntil"><block s="reportEquals"><block var="player&apos;s guess"/><block var="secret number"/></block><script><block s="doAsk"><l>Guess my number (between 1 and 10).</l></block><block s="doSetVar"><l>player&apos;s guess</l><block s="getLastAnswer"></block></block></script></block><block s="doSayFor"><l>Congratulations!  You win!</l><l>2</l></block></script><script x="11.666666666666671" y="585.5999999999999"><block s="doSayFor"><block s="reportJoinWords"><list><l>You guessed it!  My secret number was</l><block var="secret number"/></list></block><l>2</l></block></script><comment x="29.333333333333353" y="560.8000000000001" w="63.333333333333336" collapsed="false">2.7 ITIT:</comment></scripts></block-definition><block-definition s="Number guessing game with TIF B" type="command" category="other"><header></header><code></code><translations></translations><inputs></inputs><script><block s="doDeclareVariables"><list><l>secret number</l><l>maximum</l><l>number of guesses</l><l>too small responses</l><l>too big responses</l><l>last was too small?</l></list></block><block s="doSetVar"><l>too small responses</l><block s="reportNewList"><list><l>Too small!  Try again.</l><l>Still too small!</l><l>Wow, still too small!  Keep trying.</l></list><comment w="53.33333333333334" collapsed="true">TIF 3.B</comment></block></block><block s="doSetVar"><l>too big responses</l><block s="reportNewList"><list><l>Too big!  Try again.</l><l>Still too big!</l><l>Wow, still too big!  Keep trying.</l></list></block></block><block s="doAsk"><l>What&apos;s the biggest number I should use?</l></block><block s="doSetVar"><l>maximum</l><block s="getLastAnswer"></block></block><block s="doSetVar"><l>secret number</l><block s="reportRandom"><l>1</l><block var="maximum"/></block></block><block s="doSetVar"><l>number of guesses</l><l>1</l></block><block s="doAsk"><block s="reportJoinWords"><list><l>Guess my number (between 1 and </l><block var="maximum"/><l>).</l></list></block></block><block s="doSetVar"><l>last was too small?</l><block s="reportGreaterThan"><block s="getLastAnswer"></block><block var="secret number"/><comment w="53.33333333333334" collapsed="true">TIF 3.B</comment></block></block><block s="doUntil"><block s="reportEquals"><block s="getLastAnswer"></block><block var="secret number"/></block><script><block s="doChangeVar"><l>number of guesses</l><l>1</l></block><block s="doIfElse"><block s="reportLessThan"><block s="getLastAnswer"></block><block var="secret number"/></block><script><block s="doIfElse"><block var="last was too small?"><comment w="53.33333333333334" collapsed="true">TIF 3.B</comment></block><script><block s="doSetVar"><l>too small responses</l><block s="reportCDR"><block var="too small responses"/></block></block><block s="doIf"><block s="reportListIsEmpty"><block var="too small responses"/></block><script><block s="doSetVar"><l>too small responses</l><block s="reportNewList"><list><l>Too small!  Try again.</l><l>Still too small!</l><l>Wow, still too small!  Keep trying.</l></list></block></block></script></block></script><script><block s="doSetVar"><l>too small responses</l><block s="reportNewList"><list><l>Too small!  Try again.</l><l>Still too small!</l><l>Wow, still too small!  Keep trying.</l></list></block></block></script></block><block s="doSetVar"><l>last was too small?</l><block s="reportBoolean"><l><bool>true</bool></l></block></block><block s="doAsk"><block s="reportListItem"><l>1</l><block var="too small responses"/></block></block></script><script><block s="doIfElse"><block var="last was too small?"><comment w="53.33333333333334" collapsed="true">TIF 3.B</comment></block><script><block s="doSetVar"><l>too big responses</l><block s="reportNewList"><list><l>Too big!  Try again.</l><l>Still too big!</l><l>Wow, still too big!  Keep trying.</l></list></block></block></script><script><block s="doSetVar"><l>too big responses</l><block s="reportCDR"><block var="too big responses"/></block></block><block s="doIf"><block s="reportListIsEmpty"><block var="too big responses"/></block><script><block s="doSetVar"><l>too big responses</l><block s="reportNewList"><list><l>Too big!  Try again.</l><l>Still too big!</l><l>Wow, still too big!  Keep trying.</l></list></block></block></script></block></script></block><block s="doSetVar"><l>last was too small?</l><block s="reportBoolean"><l><bool>false</bool></l></block></block><block s="doAsk"><block s="reportListItem"><l>1</l><block var="too big responses"/></block></block></script></block></script></block><block s="doSayFor"><block s="reportJoinWords"><list><l>You guessed it!  My secret number was </l><block var="secret number"/><l>.  It took you </l><block var="number of guesses"/><l> guesses.</l></list></block><l>2</l></block></script><scripts><comment x="6.666666666666668" y="986.1333333333332" w="534.6666666666666" collapsed="false">There are a lot of pieces here.  Maybe the most important is the LAST WAS TOO SMALL? variable, which is needed to know whether the current guess is wrong in the same direction as the previous guess.  If so, a &quot;still too small&quot; (or big) sort of message is appropriate.  If not, just plain &quot;too small&quot; is appropriate.&#xD;&#xD;The initialization of that variable has to be such that we give a plain &quot;too small&quot; or &quot;too big&quot; the first time.  I knew that the value should depend on the small/bigness of the initial guess, but it gave me a headache trying to figure out which way the inequality should go, and I changed my mind a few times, until finally I just picked one, tried it out, and changed it when it turned out to be wrong.  This is a perfectly okay programming technique as long as you don&apos;t forget you&apos;ve made a guess that needs experimentation.&#xD;&#xD;The actual production of responses can be arbitrarily complicated!  For example, you could add a &quot;you guessed that already&quot; message.  For this solution I wrote three responses in each direction, meant to be given in order, and then just removed the first one from the list after using it (so you&apos;re always using the first one of the list as it then exists).  If the list gets empty, for the fourth consecutive error in the same direction, just restart from the initial list of three responses.  This part gives a great range for student creativity, although the big computer science idea is the variable to remember the result of the previous guess. </comment></scripts></block-definition><block-definition s="Number guessing game with high/low hints" type="command" category="other"><header></header><code></code><translations></translations><inputs></inputs><script><block s="doDeclareVariables"><list><l>secret number</l><l>maximum</l><l>number of guesses</l></list></block><block s="doAsk"><l>What&apos;s the biggest number I should use?</l><comment w="53.33333333333334" collapsed="true">3.7 ITIT</comment></block><block s="doSetVar"><l>maximum</l><block s="getLastAnswer"></block></block><block s="doSetVar"><l>secret number</l><block s="reportRandom"><l>1</l><block var="maximum"/></block></block><block s="doSetVar"><l>number of guesses</l><l>1</l><comment w="53.33333333333334" collapsed="true">TIF 3.A</comment></block><block s="doAsk"><block s="reportJoinWords"><list><l>Guess my number (between 1 and </l><block var="maximum"/><l>).</l></list></block></block><block s="doUntil"><block s="reportEquals"><block s="getLastAnswer"></block><block var="secret number"/></block><script><block s="doChangeVar"><l>number of guesses</l><l>1</l><comment w="53.33333333333334" collapsed="true">TIF 3.A</comment></block><block s="doIfElse"><block s="reportLessThan"><block s="getLastAnswer"></block><block var="secret number"><comment w="53.33333333333334" collapsed="true">3.5</comment></block></block><script><block s="doAsk"><l>Too small!  Try again.</l></block></script><script><block s="doAsk"><l>Too big!  Try again.</l></block></script></block></script></block><block s="doSayFor"><block s="reportJoinWords"><list><l>You guessed it!  My secret number was </l><block var="secret number"/><l>.  It took you </l><block var="number of guesses"/><l> guesses.</l></list></block><l>2</l><comment w="53.33333333333334" collapsed="true">TIF 3.A</comment></block></script><scripts><comment x="12.666666666666666" y="406.1333333333334" w="393.33333333333326" collapsed="false">In TIF 3.A, note that NUMBER OF GUESSES starts at 1, not 0.  Even if the REPEAT UNTIL never runs, the user still made one guess.  This sort of slightly unusual initialization is a very common source of bugs.</comment></scripts></block-definition></blocks><stage name="Stage" width="480" height="360" costume="0" color="255,255,255,1" tempo="60" threadsafe="false" penlog="false" volume="100" pan="0" lines="round" ternary="false" hyperops="true" codify="false" inheritance="true" sublistIDs="false" id="318"><pentrails>data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAeAAAAFoCAYAAACPNyggAAAAAXNSR0IArs4c6QAADoVJREFUeF7t1cEJAAAIxDDdf2m3sJ+4wEEQuuMIECBAgACBd4F9XzRIgAABAgQIjAB7AgIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECByxcQFpoRMBzwAAAABJRU5ErkJggg==</pentrails><costumes><list struct="atomic" id="319"></list></costumes><sounds><list struct="atomic" id="320"></list></sounds><variables></variables><blocks></blocks><scripts></scripts><sprites select="1"><sprite name="Sprite" idx="1" x="0" y="0" heading="90" scale="1" volume="100" pan="0" rotation="1" draggable="true" costume="0" color="80,80,80,1" pen="tip" id="325"><costumes><list struct="atomic" id="326"></list></costumes><sounds><list struct="atomic" id="327"></list></sounds><blocks></blocks><variables></variables><scripts><script x="13.333333333333337" y="6.666666666666669"><custom-block s="Number guessing game"><comment w="153.33333333333334" collapsed="false">U2L1 page 1, ex. 2&#xD;The problem doesn&apos;t say which palette category to use, so any color is okay.&#xD;&#xD;More exercise answers inside.</comment></custom-block></script><comment x="13.333333333333337" y="119" w="310.6666666666667" collapsed="false">2.1.1.5, changing values of variables.&#xD;Correct answers are 3 and -5.&#xD;&#xD;We have to teach this stuff because it&apos;s on the exam, but please don&apos;t make it the most important idea in the world.  Some years back, some researcher &quot;proved&quot; that you can predict whether someone can learn to program (ever!) based on a one-question test something like these questions.  In math class, students learn that a variable /has a single value/ and your job is to find out what that value is.  In computer science, we expect them (apparently) to understand without being taught that the values of program variables change over time.&#xD;&#xD;The irony is that we /want/ students to learn to think in terms of Functional Programming, in which the values of variables /don&apos;t/ change!  (If you call the same procedure with two different actual inputs, that&apos;s not changing the value of its formal parameter; there are /two separate variables/ with the same name but different values.&#xD;&#xD;Grrr. </comment><comment x="13.333333333333337" y="577.6666666666669" w="301.3333333333333" collapsed="false">2.1.3.1-3:  The bug is that the first time through the loop, ANSWER is still whatever value the player last guessed (from a previous game), and if that happens to be the secret number this time too, the code in the loop is never run.  Two ways to fix the bug are shown inside the definition of NUMBER GUESSING GAME, as part of the answer to 2.1, above.</comment><comment x="13.333333333333337" y="686.9999999999995" w="323.3333333333333" collapsed="false">2.1.3.5 and later.  The students will edit their NUMBER GUESSING GAME but we&apos;re starting a new one here to avoid messing up the earlier solutions.  Teachers take note that, although this is presented just as an improvement to a simple game, this introduces the binary search algorithm that will be revisited several times in later units.  (The algorithm isn&apos;t in the program, but in the optimal human player strategy.) </comment><script x="13.333333333333337" y="796.3333333333329"><custom-block s="Number guessing game with high/low hints"><comment w="90" collapsed="false">Look inside for 3.5 through TIF A.</comment></custom-block></script><script x="13.333333333333337" y="860.6666666666662"><custom-block s="Number guessing game with TIF B"><comment w="142.66666666666666" collapsed="false">TIF B is really complicated so it gets a separate solution block.</comment></custom-block></script><comment x="13.333333333333337" y="396.3333333333334" w="308.6666666666667" collapsed="false">2.1.2.4-6 predicates&#xD;Correct answers are any integer; 1,2,3,4; say nothing and report Finished.&#xD;&#xD;This is a tricky question because the code doesn&apos;t do anything sensible.  There are many ways to get in trouble because of overthinking the problem to try to make sense of it.  For example, not only does this change the value of a variable, but the variable is the input to the procedure.  Does that actually change what&apos;s entered in the input slot where the procedure is called?  No, to an experienced programmer it&apos;s obvious that that won&apos;t happen.  But to a second-week-of-intro-class student, nothing is obvious.</comment></scripts></sprite></sprites></stage><variables></variables></scene></scenes></project><media name="U2L1-NumberGuessing_SOLUTION" app="Snap! 7, https://snap.berkeley.edu" version="2"></media></snapdata>