Top Banner
A Simple Quiz for Alice 3.2: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009, added Part 2 July 2011, Edited for Alice 3 use and Part 3,4 added by Anh Trinh July 2016
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,

Sep 22, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

Quiz Procedure code