. N P ROGRA O M H T M I Y P N G Key Stage 3 COMPUTING TEACHER NOTES PART II y m U si d n a g e c Mi o d n C ecraft Pi a n d . Minecraft Pi Book Craig Richardson June 13, 2013 ThisbookislicensedundertheCreativeCommonslicenseofAttribution-NonCommercial- ShareAlike3.0Unported(CCBY-NC-SA3.0) Youarefree: toShare —tocopy,distributeandtransmitthework toRemix —toadaptthework Underthefollowingconditions: Attribution —Youmustattributetheworkinthemannerspecifiedbytheauthoror licensor(butnotinanywaythatsuggeststhattheyendorseyouoryouruseofthe work). Noncommercial —Youmaynotusethisworkforcommercialpurposes. ShareAlike —Ifyoualter,transform,orbuilduponthiswork,youmaydistributethe resultingworkonlyunderthesameorsimilarlicensetothisone. Withtheunderstandingthat: Waiver — Any of the above conditions can be waived if you get permission from the copyrightholder. PublicDomain —Wheretheworkoranyofitselementsisinthepublicdomainunder applicablelaw,thatstatusisinnowayaffectedbythelicense. OtherRights —Innowayareanyofthefollowingrightsaffectedbythelicense: • Yourfairdealingorfairuserights,orotherapplicablecopyrightexceptions andlimitations; • Theauthor’smoralrights; • Rightsotherpersonsmayhaveeitherintheworkitselforinhowtheworkis used,suchaspublicityorprivacyrights. Notice—Foranyreuseordistribution,youmustmakecleartoothersthelicense termsofthiswork. MoreinformationcanbefoundontheCreativeCommonssite: http://creativecommons.org/licenses/ Disclaimer: Anyreferenceorresemblancetotheintellectualpropertyofanindividual ororganisationisusedforeducationalpurposesonly. ThisbookisnotaffiliatedorendorsedbytheRaspberryPiFoundation,Mojang/Minecraft, Codecademyoranyorganisationmentionedinthisbook. Contents 1 Teacher’sIntroductiontotheBook 1 1.1 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.2 Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.3 KS3Curriculum . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.4 OpenSource . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 2 PythonSyntax 5 2.1 TeleportthePlayer . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.2 TeleportthePlayerPrecisely . . . . . . . . . . . . . . . . . . . . 5 2.3 TeleportationTour . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2.4 StopSmashingThings . . . . . . . . . . . . . . . . . . . . . . . 6 3 MathsOperations 7 3.1 StackingBlocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 3.2 SuperJump . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 3.3 SetBlockBelowPlayer . . . . . . . . . . . . . . . . . . . . . . . 8 3.4 SpeedBuilding . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 3.5 Proportions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 4 StringsandConsoleOutput 11 4.1 HelloMinecraftWorld . . . . . . . . . . . . . . . . . . . . . . . 11 4.2 InputtingYourMessage . . . . . . . . . . . . . . . . . . . . . . 11 4.3 UserName . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 4.4 MadLibs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 4.5 CreateaBlockwithInput . . . . . . . . . . . . . . . . . . . . . . 12 4.6 SprintRecord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 5 ComparatorsandControlFlow 15 5.1 Swimming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 5.2 Doyouwanttostopsmashingthings? . . . . . . . . . . . . . 15 5.3 BringusaShrubbery . . . . . . . . . . . . . . . . . . . . . . . . 16 i ii CONTENTS 5.4 TakeaShower . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 5.5 SecretPassage . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 6 Functions 19 6.1 AForest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 6.2 ArmingTNT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 6.3 WoolColour . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 6.4 Turtle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 6.5 ImportBlockModule . . . . . . . . . . . . . . . . . . . . . . . . 25 7 ListsandDictionaries 27 7.1 GlitchingSigns . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 7.2 BlocksbyNumbers . . . . . . . . . . . . . . . . . . . . . . . . . 27 7.3 TeamCamera . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 7.4 DictionaryofWool . . . . . . . . . . . . . . . . . . . . . . . . . . 29 7.5 HackaFriend’sGame . . . . . . . . . . . . . . . . . . . . . . . . 30 8 FunctionsandLists 31 8.1 PixelArt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 8.2 ShadowCastle . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 9 Loops 35 9.1 MidasTouch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 9.2 TreeFighter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 9.3 ChatwithaLoop . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 9.4 Pyramid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 9.5 HotandCold . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 9.6 AdaptExercises . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 10 AdvancedTopicsinPython 39 11 BinaryandBitwiseOperators 41 12 Classes 43 13 FileinputandOutput 45 Chapter 1 Teacher’s Introduction to the Book This is the teacher’s edition of the Python Programming with Minecraft Pi and Codecademy book. It includes an explanation of the main book and suggested answers to each exercise. You will find the answers from Chapter2onwards. TheMinecraftPiPythonbookisintendedtosupportlearnersastheylearn to program with Python. The material is split into two categories: ex- ercises and reference. Reference materials concentrate on the low-level skillsofrememberingandunderstanding,whereasexercisesfocusonthe higher-level skills of application, problem solving, analysis, evaluation andcreation. All exercises use Minecraft Pi edition on the Raspberry Pi to provide a fun and challenging environment for students to practice and develop their programming skills. The main focus of exercises is problem solv- ing,whichisanessentialprogrammingskill. Studentsshouldbeencour- agedtodeviatefromthebriefanddeveloptheirownideasascreativityis another essential skill for programmers. Share your students’ ideas for programsandImightincludetheminfutureversionsofthebook. 1.1 Exercises Atthestartofeverychapterthereareasetofexercisesthathelplearners developtheirprogrammingskills. Theemphasisoftheexercisesistoap- plytheknowledgeandunderstandinginordertocreateaprograms. All programming exercises are challenging and differentiated. Instead 1 2 CHAPTER 1. TEACHER’S INTRODUCTION TO THE BOOK of merely telling the student to copy code, each exercise sets the player a challenge with instructions of varying difficulty. They apply concepts learnedinthecurrentchapterandcorrespondingCodecademylessonto solve these challenges and gain problem solving skills. Extension exer- cises are included with every exercise, enabling students who are more comfortablewiththeexercisestodevelopfurther. This version of the book uses Minecraft Pi on the Raspberry Pi to prac- ticeprogramminginexercises. TheRaspberryPiisanexcellent,low-cost computer designed to teach programming. It has a strong, enthusiastic communityandisanexcellentwaytogetstartedprogramming. Minecraft Pi edition is an official version of Minecraft that has been de- velopedfortheRaspberryPi. ThankstoitsamazingdevelopersatMojang, it is free software and has a special feature, an API, that allows users to control the game with programming. It is very simple to use and gives learnersaveryengagingandcreativewaytopracticeprogramming. 1.2 Reference Thereferencepartsofthebooksupportalearner’sabilitytounderstand and remember concepts. However, they are not intended to be used in isolation. TheyweredesignedtosupportthePythontrackatCodecademy. Codecademyisafreeonlinelearningsystemthatgiveslearnershands-on experienceandguidancewithprogramming. ThereferencepartsofthebookareintendedasasupplementtotheCodecademy lessonsinanumberofways: • Extra support for students who need help understanding concepts introducedinCodecademy • Referenceforlearnerswhentheyaredevelopingtheirownprograms • Revisionmaterialsforstudentsundertakingassessment Ofcourseitispossibletoreadthebookfromstarttofinish,howeverthere isnothingbetterthangaininghands-onexperienceofprogramming. IfyouareateacherIcannotrecommendCodecademyenough. Duetothe structure of the site it provides exactly the right support for a beginner meaningtheyrequirelessdirectinterventionfromyou. Asyounolonger 1.3. KS3 CURRICULUM 3 needtoprovidedebuggingadviceandmarkingforallyourstudentsyou can use your time more effectively and support the students that really need your help. Monitoring progress and providing clear targets to stu- dentsisessentialforeffectiveprogressionthroughthesite. 1.3 KS3 Curriculum NotallofthetopicscoveredintheCodecademyPythontrackandthebook areessentialfortheUKKeyStage3draftComputingcurriculum. Ihave summarisedwhatIbelievearethemostimportantunits/chapters: 1. Datatypesandmathsoperators 2. Stringandcommandlineinputandoutput 3. BooleanLogic,ConditionalsandIfstatements 4. Functions 5. Lists 6. Loops Furthermore, within each of these topics there are concepts which I be- lieveareaminimumrequirementforstudentstounderstandandanum- berofmoreadvancedtopics. Forexampleinthelistsunitstudentsshould at a minimum understand the purpose of lists, index positions and ac- cessing/changinglistvalues. Intermediateknowledgeincludeloopswith lists, appendingitems andremovingitems. Advancedtopicsincludelist slicingandsoon. Abreakdownoftheselevelsofunderstandingbytopic maybeincludedinafutureupdateofthisbook. Ofcourseyoushouldencourageyourstudentstogofurtheriftheyhave thetimeandenthusiasm. In a future draft I will state how each topic of the curriculum is covered in the book. There will of course be some gaps, which will eventually be filledbyotherresources. Thematerialcanalsobeusedforadifferentcurriculumasprogramming conceptsstaythesame. 4 CHAPTER 1. TEACHER’S INTRODUCTION TO THE BOOK 1.4 Open Source The book is open source, meaning anyone can change and modify it as they please. A creative commons license is used, which carries some re- strictions. Details of the license of the book can be found at the start of thebook. The book is written in LaTeX, a free, open-source typesetting language. If you’re not familiar with LaTeX, it is similar to HTML in that it formats text. AguidetogettingstartedwithLaTeXcanbefoundviaGooglesearch and an explanation of the conventions used in the book can be found in thefirstchapter. Thebookwasdesignedsothatdifferentexercisescanbeswappedintothe book. Sayyoudon’twanttoteachstudentswithMinecraftPi,youwantto useSimpleCV,BlenderorPyGame. Dothis. Createyourownexercisesand swapthemfortheonesinthebookandwenowhaveadifferenteditionof thesamebookthatotherpeoplewillfinduseful. Allofthereferencema- terialscanstaythesameastheymakenomentionofMinecraftPi.