KS2: Python Programming Unit - Primary Computing

3y ago
105 Views
5 Downloads
4.93 MB
33 Pages
Last View : Today
Last Download : 3m ago
Upload by : Mara Blakely
Transcription

For free Primary Computing resources please visit KS2: PythonProgramming UnitJon Chippindall@drchipswww.primarycomputing.co.uk

For free Primary Computing resources please visit IntroductionThis document sets out a scheme of work aimed to introduceupper Key Stage 2 pupils to the Python programming language.The scheme intends to familiarise pupils with the Pythonprogramming environment and syntax, and equip pupils with theskills and knowledge to write simple programs.It is anticipated that pupils will have had prior experience of codingusing a visual based programming language, such as Scratch orKodu, and that this is likely to be the first time they will code usinga scripting language. i.e. writing lines of code as opposed todragging blocks to build algorithms and programs. The examplebelow illustrates the difference between a visual programminglanguage and a scripting language.An if/else condition block in Scratch and the equivalent coding in PythonPedagogyThere are four lessons in this scheme of work followed by a finalproject. Lessons broadly follow a model in which skills andknowledge are taught using worked/modelled examples beforepupils tackle a ‘Coding Challenge’ requiring application of suchskills and knowledge. Whilst suggested ‘Coding Challenges’ havebeen presented here, I encourage those using this resource toalso generate coding challenges for pupils (or encourage pupils togenerate their own challenges), which may link into areas of pupils’topic work making the programming more relevant to pupils’ widerlearning. Similarly, whilst two suggestions have been made for thefinal project, it is anticipated that teachers using this resourcesmay choose to adapt these for their pupils or encourage pupils togenerate their own ideas for the final project programs they wish tocode.

For free Primary Computing resources please visit Whilst answers to ‘Coding Challenges’ are presented, it should benoted that there will often be different ways to program asuccessful solution, and pupils should be encouraged toexperiment and explore their own methods as opposed to beingfunnelled towards a predefined solution, since it is the journey ofexperimentation, trial and error that will facilitate learning.It is hoped class and school organisation will be such that pupilsare given the opportunity to tackle some challenges independentlyand others cooperatively, helping to develop pupils’ collaborativeskills as well as independent perseverance and resilience inproblem solving.Proposed Computing National Curriculum coverageThis scheme aims to cover the following objectives from theproposed Key Stage 2 National Curriculum for Computing. SpecificNC objectives appear at the beginning of each lesson. design and write programs that accomplish specific goals; solve problemsby decomposing them into smaller parts use sequence, selection, and repetition* in programs; work with variablesand various forms of** input and output; generate appropriate inputs andpredicted outputs to test programs use logical reasoning to explain how a simple algorithm works and todetect and correct errors in algorithms and programs* Note this scheme does not cover repetition (loops)** This scheme only covers one form of input/output (that of the program userentering data via a keyboard)Lesson OverviewLesson1.IntroducingPythonLesson objectives- Navigate Idle (create, save, runprograms)Understandandusemathematical operation and visualprogramminglanguage, syntax,Idle2. Variables andcomments-Declare a variablevariables, declare,comment-Write comments within Pythoncode-Use mathematical operations andprint statement with variables

For free Primary Computing resources please visit 3. User inputs- Use raw input() statement- Use input() statement- Print sentencesInput4. Selection andinequalities-Use conditional statements if, elseif (elif) and else-Use comparison operatorsconditionalstatement,comparisonoperator5. Final projectReinforcement and application ofskills and knowledge coveredaboveVocabularyA glossary of terms used throughout this SoW is included at theend of this document. Any term appearing in bold in lesson plansappears in the glossary and should be introduced to pupils usingthe definition provided.It is suggested that starters including matching words withdefinitions or code are used to help develop pupils’ knowledge ofthe technical terminology of coding and the syntax of Python.Code representation and line numberingWithin this document Python code to be written appears in adifferent font as shown below. Also note that lines of code arenumbered for ease of reference within the text however you donot include these numbers when coding. Code that would be onelong line in Python but which spans several lines when presentedhere does not start with a new number to indicate this. Finally,please note that Python reads the indentation of code so layout isimportant (i.e. in the example below ‘print’ is deliberately indented).1.num1 input(“Pleaseenteranumber”)2.num2 input(“Pleaseenterasecondnumber”)3.ifnum1 l resourcesAt the end of this document there are pupil resources to print toaccompany each lesson with the model code and CodingChallenges.

For free Primary Computing resources please visit Lesson 1: Introducing PythonL.Os:1. Navigate Idle (create, save, run programs)2. Understand and use mathematical operation and ‘print’statementN.C: usesequenceinprograms;Vocabulary: Python, scripting language, visual programminglanguage, syntax, IdleIntroducing Python and mathematical functions: Explain thatpupils will be using a language called Python to write programs.Recap that pupils will have had prior experience of writingprograms using Scratch, which is a visual programminglanguage as we built up programs by visually draggingprogramming blocks.Explain that Python is a scriptinglanguage, so instead of dragging blocks we have to write codeand we have to learn the language of Python’s code (called thesyntax) - just like we may learn languages such as French ofUrdu.Ask pupils to open Idle (which is on both Windows and Mac).Explain this is a program we use to write our Python codes.Introduce the following code to pupils:Mathematical Python code */Demonstrate that we can use this code to communicate in Pythonto work out numeracy calculations for us. For example, try writingthe following into Idle and press return after each. Give time forpupils to try using Python to complete calculations.300 400987-65312*930/6

For free Primary Computing resources please visit Hello World program: We are now going to move on to teachingpupils how to write a program to display text within Python. Whenrun, the text displayed will read ‘Hello World’, as traditionally this isthe first program anyone learns to write in a new programminglanguage!To do this (and from here onwards when programming in Python)we are not going to write our code in the ‘outer’ Idle window wehave just been using but rather from within Idle ask pupils to selectFile New Window to create a window which we can code intoand save. Show in the screenshots below. From this newwindow, pupils should click File Save and name the filehelloworld.py. Explain it is important to include the .py fileextension to indicate this is a Python file. Ask pupils to save the fileto an appropriate location.3 screenshots showing outer window of Idle (Python shell) then opening anew window to write programs into.Similarly to introducing the code for mathematical operationsabove, introduce pupils to the statement ‘print””’. Explain thatwhen using the statement ‘print””’ programs will display the textwith the quotation marks. So to create a ‘Hello World’ program askpupils to write the following code into the window. Note there is nocapital P for the statement print. This is important as Python is acase-sensitive language.1. print “Hello world!”Once pupils have written this line of code, explain that to run theirprogram they must first save the changes they have made to theirfile. Once they have done this, they must select ‘Run’ then ‘RunModule’.

For free Primary Computing resources please visit The window they have been coding in will close and their programwill run in the ‘outer’ Python window we used earlier. If they havetyped the code correctly their program will display the words ‘HelloWorld!’. They’ve now written their first Python program!Coding Challenge: Can pupils write a program which displaysmore lengthily text on different lines? For example:Hello, how are you today?I hope you are enjoying learning Python.What shall we code next?Challenge solution: Pupils need to use the ‘print’ statement oneach new line to display text over several lines. e.g. Remembernot to include the numbers1.print “Hello, how are you today?”2.print “I hope you are enjoying learning Python”3.print “What shall we code next?”

For free Primary Computing resources please visit Lesson 2: Variables and commentsL.Os:1. Declare a variable2. Write comments within Python code3. Use mathematical operations and print statement withvariablesN.C: design and write programs that accomplish specific goals; use sequence inprograms; work with variables and output; generate appropriate inputs andpredicted outputs to test programs; use logical reasoning to explain how a simplealgorithm works and to detect and correct errors in algorithms and programs.Vocabulary: variables, declare, commentIntroducing variables: Explain to pupils that variables may bethought of as boxes within our program where we can place data(numbers or text). Explain that we can then use the contents of theboxes within our program and that the values assigned to ourvariable (the contents of our boxes) may change as our programruns.We need to name ourvariable e.g. variable1A variable may bethough of as a boxwhere we place data foruse in our programse.g.‘Hello world’‘4.78’Explain that when we create a variable and assign data (get a boxand put something in it) it is called declaring a variable.Demonstrate that to declare a variable we use the following code:1.variable1 8Explain that in this example above we have created a variablecalled ‘variable1’ and assigned the value 8 to it. Demonstrate thatwe can create more than one variable and that we can assign textas well as numbers to variables by writing the following code:

For free Primary Computing resources please visit 1.name sarah2.laps 8Can pupils names the 2 variables you have created using the codeabove and their values? Explain here that naming variables withnames that relate to the data they hold (e.g. name & laps), asopposed to using generic terms such as variable1, makessubsequently writing code using these variables easier.Ask pupils to now create a new Python file: i.e. open Idle, selectFile New window then Save as, and call the file variables.py andsave to an appropriate location.Ask pupils to create a variable called ‘children’ with a value of 30and a variable called ‘sweets’ with a value of 5. Explain that we willbe using these variables to write a program that calculates the totalnumber of sweets required to give a defined number of sweets to adefined number of children.Solution code:1.children 302.sweets 5Comments in Python: Explain that a comment is a line of codethat isn’t part of the program but is there to explain to theprogrammer what parts of the code are doing. We write commentsin regular clear English (or whatever language we as programmersmay speak) as opposed to the language of Python. Explain thatcomments are important as when we write longer pieces of codewe may forget the function of different parts, or we may work oncode collaboratively with others and therefore we need to explainwhat we are doing.However, explain that the trouble with writing in regular Englishwithin our program is that our computer thinks we are still writing inPython and may try and interpret commands from what we havesaid. As such, we need to indicate when we are writing a commentand we do that by using ‘#’. Explain that the computer will ignoreany line starting with # as it knows this is a comment to theprogrammer and not part of the code. Demonstrate addingcomments to the variable we just created to add explanation aboutwhat we are coding and ask the children to do the same i.e.

For free Primary Computing resources please visit 1.children 302.#The number of children in the class3.sweets 54.#The number of sweets each child will getUsing mathematical operations and print statement withvariables: Explain we are now going to continue coding to write aprogram that uses the variables we have just declared as well asthe mathematical operations and print statement we covered in theprevious lesson.Recap that the purpose of this program was to work out the totalnumber of sweets required based on the two variables we havedeclared: the number of children and the number of sweets theyget each.To write the program to calculate this, add the code beneath ourvariables and comments that appears on line 4&5 below and ishighlighted for clarity – and ask pupils to add the same to theirprogram.1.children 302.#The number of children in the classsweets 53.#The number of sweets each child will get4. total children*sweets5. print totalTake a moment to discuss with pupils lines 4&5 of code above.Can children spot a new variable being declared? What is thename of this new variable? Can children spot the mathematicaloperator? What mathematical operation is it? (Note the scope hereto reinforce numeracy problem solving objectives on choice ofoperation) Can pupils see the print statement we used in lesson 1?Note – we don’t need to use quotation marks when requesting toprint a variable.What do pupils anticipate the output

upper Key Stage 2 pupils to the Python programming language. The scheme intends to familiarise pupils with the Python programming environment and syntax, and equip pupils with the skills and knowledge to write simple programs. It is anticipated that pupils will have had prior experience of coding using a visual based programming language, such as Scratch or Kodu, and that this is likely to be .

Related Documents:

Python Programming for the Absolute Beginner Second Edition. CONTENTS CHAPTER 1 GETTING STARTED: THE GAME OVER PROGRAM 1 Examining the Game Over Program 2 Introducing Python 3 Python Is Easy to Use 3 Python Is Powerful 3 Python Is Object Oriented 4 Python Is a "Glue" Language 4 Python Runs Everywhere 4 Python Has a Strong Community 4 Python Is Free and Open Source 5 Setting Up Python on .

Every school has the right to choose the content which they feel is suitable for their students. This will be dependent on social need, maturity, and their environment. . KS1 L3 KS1 R8 KS1 R13 KS1 R14 KS2 L6 KS2 R10 KS2 R14 KS2 R16 KS2 R18 KS2 R21 Keeping/Staying Safe Module Staying Safe Computer Safety Module

Python 2 versus Python 3 - the great debate Installing Python Setting up the Python interpreter About virtualenv Your first virtual environment Your friend, the console How you can run a Python program Running Python scripts Running the Python interactive shell Running Python as a service Running Python as a GUI application How is Python code .

Python is readable 5 Python is complete—"batteries included" 6 Python is cross-platform 6 Python is free 6 1.3 What Python doesn't do as well 7 Python is not the fastest language 7 Python doesn't have the most libraries 8 Python doesn't check variable types at compile time 8 1.4 Why learn Python 3? 8 1.5 Summary 9

site "Python 2.x is legacy, Python 3.x is the present and future of the language". In addition, "Python 3 eliminates many quirks that can unnecessarily trip up beginning programmers". However, note that Python 2 is currently still rather widely used. Python 2 and 3 are about 90% similar. Hence if you learn Python 3, you will likely

There are currently two versions of Python in use; Python 2 and Python 3. Python 3 is not backward compatible with Python 2. A lot of the imported modules were only available in Python 2 for quite some time, leading to a slow adoption of Python 3. However, this not really an issue anymore. Support for Python 2 will end in 2020.

Python Programming - This is a textbook in Python Programming with lots of Practical Examples and Exercises. You will learn the necessary foundation for basic programming with focus on Python. Python for Science and Engineering - This is a textbook in Python Programming with lots of Examples, Exercises, and Practical Applications

CR ASH COURSE PY THON CR ASH COURSE 2ND EDITION ERIC MATTHES SHELVE IN: PROGRAMMING LANGUAGES/ PYTHON 39.95 ( 53.95 CDN) LEARN PYTHON— FAST! COVERS PYTHON 3.X Python Crash Course is the world's best-selling guide to the Python programming language. This fast-paced, thorough introduction to programming with Python will