a simple quiz for alice 3.2 · 2011. 7. 2. · a simple quiz for alice 3.2: ask user functions. by...
TRANSCRIPT
![Page 1: A Simple Quiz for Alice 3.2 · 2011. 7. 2. · A Simple Quiz for Alice 3.2: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009,](https://reader033.vdocuments.mx/reader033/viewer/2022051807/6003ceeb104ada0ca2296838/html5/thumbnails/1.jpg)
ASimpleQuizforAlice3.2:AskUserFunctions.
ByLanaDyckunderthedirectionofProfessorSusanRodger
DukeUniversityJune2009,addedPart2July2011,
EditedforAlice3useandPart3,4addedbyAnhTrinhJuly2016
![Page 2: A Simple Quiz for Alice 3.2 · 2011. 7. 2. · A Simple Quiz for Alice 3.2: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009,](https://reader033.vdocuments.mx/reader033/viewer/2022051807/6003ceeb104ada0ca2296838/html5/thumbnails/2.jpg)
Introduction and Set-up
Thistutorialwilldemonstratehowtocreateasimplequizusingthethreedifferentkindsof“askuser”functions:askuserforanumber,askuserfortrueorfalseandaskuserforastring.
OpenanewAlicegrassworld.ClickonSetupScene.ChooseBrowseGalleryByGroup,and
clickAnimals.AddonePenguin,oneCow,andthree
Chickens intoyourworld.Arrangeandresizetheobjectsso
theyareeasytosee.ClickEditCodewhenfinished.
Let'sgetstartedbysettinguptheworld.
![Page 3: A Simple Quiz for Alice 3.2 · 2011. 7. 2. · A Simple Quiz for Alice 3.2: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009,](https://reader033.vdocuments.mx/reader033/viewer/2022051807/6003ceeb104ada0ca2296838/html5/thumbnails/3.jpg)
Createanewsceneprocedurethatwewilluselatertoholdtheinstructionsforthequiz.
Step 1: Create the Quiz Procedure
Letsstartbycreatingaquizprocedure
ClickontheScene tabandchooseAddSceneProcedure
Namethenewprocedure:quiz.
ClickbackonmyFirstMethod.
![Page 4: A Simple Quiz for Alice 3.2 · 2011. 7. 2. · A Simple Quiz for Alice 3.2: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009,](https://reader033.vdocuments.mx/reader033/viewer/2022051807/6003ceeb104ada0ca2296838/html5/thumbnails/4.jpg)
NowwewilladdthequiztoMyFirstMethod.
MakesureyouareinMyFirstMethod.
Clickonthis.penguin intheobjecttree.
Dragthesay procedureintotheprocedureeditorandtypein:Timeforaquiz.
Draginasecondsay procedureandtypein:Thatisallfolks!
Clickonthis intheobjecttreeanddragthequiz procedureinbetweenthetwopenguinsaycommands
Step 2: Set Up MyFirstMethod
![Page 5: A Simple Quiz for Alice 3.2 · 2011. 7. 2. · A Simple Quiz for Alice 3.2: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009,](https://reader033.vdocuments.mx/reader033/viewer/2022051807/6003ceeb104ada0ca2296838/html5/thumbnails/5.jpg)
Nowwewillstartwritingthequizprocedure.Tomakeourcodeeasiertoreadwewilladdincomments.Commentsmakeitpossibletoaddinnotesaboutthecodelike,whatitwilldo,orwhowrotethecode.
Firstclickonthequizproceduretab.
Toaddacommentdraganddropthedoubleslashbuttonintothemethod
Step 3: Comments
![Page 6: A Simple Quiz for Alice 3.2 · 2011. 7. 2. · A Simple Quiz for Alice 3.2: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009,](https://reader033.vdocuments.mx/reader033/viewer/2022051807/6003ceeb104ada0ca2296838/html5/thumbnails/6.jpg)
Typeinthecommenteditor:Question1
Clickonthis.penguin intheobjecttree,haveitsay:Howmanyanimalsintheworld?andsetthedurationto2seconds.
Step 4: Question #1
Weneedavariabletostorethenumberinformationwegetfromtheuser.
Draginthebuttontoopenvariableoptionbox.
NameitanswerNumber.SelectWholeNumberbesidevaluetype,initializeitto0andclickOK.
![Page 7: A Simple Quiz for Alice 3.2 · 2011. 7. 2. · A Simple Quiz for Alice 3.2: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009,](https://reader033.vdocuments.mx/reader033/viewer/2022051807/6003ceeb104ada0ca2296838/html5/thumbnails/7.jpg)
Clickontheworld intheobjecttree.Undertheworld'sdetails,functions find“askuserforanumber.”Clickanddragtheaskuserforanumber overthe1andselectother...Enterthestring:Enterthenumberofanimals:
Step 4: Question #1Continued...
![Page 8: A Simple Quiz for Alice 3.2 · 2011. 7. 2. · A Simple Quiz for Alice 3.2: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009,](https://reader033.vdocuments.mx/reader033/viewer/2022051807/6003ceeb104ada0ca2296838/html5/thumbnails/8.jpg)
Nowwewilldeterminewhathappensiftheanswergiveniscorrectorincorrect.
DraganddropanIf blockfromthebottomofthewindowandsetittotrue.
Step 4: Question #1Continued...
ChooseRelational(WholeNumber)inthetruedrop-downlist.
Select“???==???“->answerNumber...->CustomWholeNumbertoenterinthevalue5.5isthecorrectanswertothisquestion.
![Page 9: A Simple Quiz for Alice 3.2 · 2011. 7. 2. · A Simple Quiz for Alice 3.2: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009,](https://reader033.vdocuments.mx/reader033/viewer/2022051807/6003ceeb104ada0ca2296838/html5/thumbnails/9.jpg)
Forthisquestionwhenthe“If”statementistrue,theansweriscorrect.Sowewillputourresponsetothecorrectanswerfirst.
Clickonthis.penguin intheobjecttree.UndertheIf:Dragthesay methodandtype:CorrectDragtheturn methodandselect1
Whentheifstatementisfalse,theanswerisincorrect.
UndertheElse:Dragthesay methodandtype:Sorry,thatisnotcorrect.
Step 4: Question #1Continued...
Runyourworldtotaketheonequestionquiz.
![Page 10: A Simple Quiz for Alice 3.2 · 2011. 7. 2. · A Simple Quiz for Alice 3.2: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009,](https://reader033.vdocuments.mx/reader033/viewer/2022051807/6003ceeb104ada0ca2296838/html5/thumbnails/10.jpg)
Nowletsmakeaquestionthataskstheuserforatrueorfalseresponse.
Dropinacommentandtypein:Question2Clickonpenguin intheobjecttree,haveitsay:Aretheremorechickensthanpenguins?andsetthedurationto2seconds.
Step 5: Question #2
Weneedavariabletostorethebooleaninformationwegetfromtheuser.
Draginvariable buttonfromthebottomofthewindow.
NameitanswerBoolean.
SelectBooleanandClickOK.
![Page 11: A Simple Quiz for Alice 3.2 · 2011. 7. 2. · A Simple Quiz for Alice 3.2: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009,](https://reader033.vdocuments.mx/reader033/viewer/2022051807/6003ceeb104ada0ca2296838/html5/thumbnails/11.jpg)
Inthepenguin'sfunctions,draganddropthe“getBooleanFromUser”overthetrue.
Typein:Clickontrueandfalse.
Step 5: Question #2Continued...
![Page 12: A Simple Quiz for Alice 3.2 · 2011. 7. 2. · A Simple Quiz for Alice 3.2: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009,](https://reader033.vdocuments.mx/reader033/viewer/2022051807/6003ceeb104ada0ca2296838/html5/thumbnails/12.jpg)
NowwewilladdinourresponsestotheanswerinanotherIf/Elsestatement.
DraganddropanIf/ElsestatementandselectanswerBoolean.
TheIfquestionacceptsjustthevariablebecauseanswerBooleanisabooleantype.
Step 5: Question #2Continued...
![Page 13: A Simple Quiz for Alice 3.2 · 2011. 7. 2. · A Simple Quiz for Alice 3.2: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009,](https://reader033.vdocuments.mx/reader033/viewer/2022051807/6003ceeb104ada0ca2296838/html5/thumbnails/13.jpg)
Nowcompletethequestion#2byaddingintheproceduresasshownbelow:
Step 5: Question #2Continued...
Runyourworldtotakethetwoquestionquiz.
![Page 14: A Simple Quiz for Alice 3.2 · 2011. 7. 2. · A Simple Quiz for Alice 3.2: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009,](https://reader033.vdocuments.mx/reader033/viewer/2022051807/6003ceeb104ada0ca2296838/html5/thumbnails/14.jpg)
Forourfinalquestionwewillasktheusertoenterastring.
Dropinacommentandtypein:Question3
Clickonpenguin intheobjecttree,haveitsay:Whatbuildingarewein?andsetthedurationto2seconds.
Step 6: Question #3
Weneedavariabletostorethestringinformationwegetfromtheuser.
Draginthevariable button.
NameitanswerString.
SelectTextStringand‘hello’ininitializerClickOK.
Note: Astringisasetoflettersorcharacters.Aspaceisconsideredacharactersobecarefulifyouhaveaspaceattheendofyourwordorsentence.
![Page 15: A Simple Quiz for Alice 3.2 · 2011. 7. 2. · A Simple Quiz for Alice 3.2: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009,](https://reader033.vdocuments.mx/reader033/viewer/2022051807/6003ceeb104ada0ca2296838/html5/thumbnails/15.jpg)
Inthepenguin'sfunctions,draganddropthegetStringFromUser overthe‘hello’string.
Typein:Enteracronym.
Step 6: Question #3Continued...
![Page 16: A Simple Quiz for Alice 3.2 · 2011. 7. 2. · A Simple Quiz for Alice 3.2: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009,](https://reader033.vdocuments.mx/reader033/viewer/2022051807/6003ceeb104ada0ca2296838/html5/thumbnails/16.jpg)
NowwewilladdinourresponsestotheanswerinanotherIf/Elsestatement.
DraganddropanIf/Else statementandselecttrue.
ClickthedownarrowintrueandselectTextStringComparison->???equalsIgnoreCase???-> answerString-> CustomTextString thentypein:LSRC
WithequalsIgnoreCase,theanswerisnotcase-sensitive
Step 6: Question #3Continued...
![Page 17: A Simple Quiz for Alice 3.2 · 2011. 7. 2. · A Simple Quiz for Alice 3.2: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009,](https://reader033.vdocuments.mx/reader033/viewer/2022051807/6003ceeb104ada0ca2296838/html5/thumbnails/17.jpg)
Clickonpenguinintheobjecttreeandaddintheresponsesforwhentheansweriscorrectorincorrectasshownbelow.
Nowplayyourworldandtakethequiz.
Step 6: Question #3Continued...
![Page 18: A Simple Quiz for Alice 3.2 · 2011. 7. 2. · A Simple Quiz for Alice 3.2: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009,](https://reader033.vdocuments.mx/reader033/viewer/2022051807/6003ceeb104ada0ca2296838/html5/thumbnails/18.jpg)
Part 2: Forcing the Answer
InQuestion1,iftheusermistypestheanswer,wewanttheprogramtoasktheuserfortheansweragainuntilitiscorrect.Rewritequestion1toaddawhileloopandforcetheuserintotheloopwithawrongvaluetostartwith.
![Page 19: A Simple Quiz for Alice 3.2 · 2011. 7. 2. · A Simple Quiz for Alice 3.2: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009,](https://reader033.vdocuments.mx/reader033/viewer/2022051807/6003ceeb104ada0ca2296838/html5/thumbnails/19.jpg)
Part 3: Limiting Number of Trials
Tolimitthenumberoftrialsto3forexample,createanewvariablenamednumberofTrial,createawhileloopthatallowsthequestiontoshowupaslongasthestudentstrieslessthan3times.Eachtimetheyanswerincorrectly,incrementnumberofTrial by1.Iftheyanswer,correctly,setnumberofTrial toanumbergreaterthan3tobreakoutofthewhileloop(herewechoose5)
![Page 20: A Simple Quiz for Alice 3.2 · 2011. 7. 2. · A Simple Quiz for Alice 3.2: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009,](https://reader033.vdocuments.mx/reader033/viewer/2022051807/6003ceeb104ada0ca2296838/html5/thumbnails/20.jpg)
Part 4: Score Reporting
Challenge:Toreportscoretouser,wehavetocreatealocalvariablescore forthequizprocedure,initializeitto0,andincrementitby1everytimethestudentansweraquestioncorrectly.Attheend,havethepenguinreportthescore.
![Page 21: A Simple Quiz for Alice 3.2 · 2011. 7. 2. · A Simple Quiz for Alice 3.2: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009,](https://reader033.vdocuments.mx/reader033/viewer/2022051807/6003ceeb104ada0ca2296838/html5/thumbnails/21.jpg)
Toreportthescoreintheend,dragthepenguinsayprocedureinandtype“Yougot”.
Clickonthedownarrownexttothestringyoujusttypedandselect“Yougot“+???->WholeNumber->score
Part 4: Score Reporting
![Page 22: A Simple Quiz for Alice 3.2 · 2011. 7. 2. · A Simple Quiz for Alice 3.2: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009,](https://reader033.vdocuments.mx/reader033/viewer/2022051807/6003ceeb104ada0ca2296838/html5/thumbnails/22.jpg)
Clickonthedownarrownexttothe“Yougot“+scorestringandselect“Yougot“+score+??? ->CustomTextString andType”questionscorrect”
Part 4: Score Reporting
![Page 23: A Simple Quiz for Alice 3.2 · 2011. 7. 2. · A Simple Quiz for Alice 3.2: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009,](https://reader033.vdocuments.mx/reader033/viewer/2022051807/6003ceeb104ada0ca2296838/html5/thumbnails/23.jpg)
Quiz Procedure code