Log onto a computer first then …. Do it now – page 8 Log onto a computer first then …. Go back to your normal desk, find your do it now task in your workbook – look for the start button! Friday, 30 November 2018
Sub-solution using procedures
Learning Objective “Find out how a procedure can be used to hide the detail in your programs” You will find differentiated outcomes for this lesson on the front of your workbook. Friday, 30 November 2018
FACT: Programmers are Lazy! Sub-solution procedure New Learning FACT: Programmers are Lazy! Sub-solution procedure Explain that sub-solution is used to hide the detail in your programs but also to make it possible to re-use code. We will learn about one type of sub-solution today called a procedure Find out how a procedure can be used to hide the detail in your programs
New Learning square() right(70) from turtle import * def square(): forward(100) right(90) square() right(70) This is an example of a program that includes a procedure Find out how a procedure can be used to hide the detail in your programs
New Learning def square(): forward(100) right(90) here is a closer look at the procedure – you will have noticed that it has been called square and has a number of instructions built into it I will now run through the code showing you what is happening Find out how a procedure can be used to hide the detail in your programs
New Learning square() right(70) forward(100) Here is the rest of the program, you will notice that the first instruction is a call to the procedure – so control switches to the procedure Find out how a procedure can be used to hide the detail in your programs
New Learning def square(): forward(100) right(90) control is passed to the procedure that has been called and the computer executes each instruction in order inside the procedure Find out how a procedure can be used to hide the detail in your programs
New Learning def square(): forward(100) right(90) Find out how a procedure can be used to hide the detail in your programs
New Learning def square(): forward(100) right(90) Find out how a procedure can be used to hide the detail in your programs
New Learning def square(): forward(100) right(90) Find out how a procedure can be used to hide the detail in your programs
New Learning def square(): forward(100) right(90) Find out how a procedure can be used to hide the detail in your programs
New Learning def square(): forward(100) right(90) Find out how a procedure can be used to hide the detail in your programs
New Learning def square(): forward(100) right(90) Find out how a procedure can be used to hide the detail in your programs
New Learning def square(): forward(100) right(90) We have got to the end of the procedures code so control passes back to the main part of the program (or the main method) Find out how a procedure can be used to hide the detail in your programs
New Learning square() right(70) forward(100) the instructions in the main method continue to be executed in order Find out how a procedure can be used to hide the detail in your programs
New Learning square() right(70) forward(100) Find out how a procedure can be used to hide the detail in your programs
New Learning square() right(70) forward(100) once again the procedure square has been called so control is again passed to the procedure Find out how a procedure can be used to hide the detail in your programs
New Learning def square(): forward(100) right(90) This is an example of a procedure Find out how a procedure can be used to hide the detail in your programs
New Learning def square(): forward(100) right(90) This is an example of a procedure Find out how a procedure can be used to hide the detail in your programs
New Learning def square(): forward(100) right(90) This is an example of a procedure Find out how a procedure can be used to hide the detail in your programs
New Learning def square(): forward(100) right(90) This is an example of a procedure Find out how a procedure can be used to hide the detail in your programs
New Learning def square(): forward(100) right(90) This is an example of a procedure Find out how a procedure can be used to hide the detail in your programs
New Learning def square(): forward(100) right(90) This is an example of a procedure Find out how a procedure can be used to hide the detail in your programs
New Learning def square(): forward(100) right(90) This is an example of a procedure Find out how a procedure can be used to hide the detail in your programs
New Learning def square(): forward(100) right(90) This is an example of a procedure Find out how a procedure can be used to hide the detail in your programs
New Learning square() right(70) forward(100) We have reached the end of the program and so the computer stops working. Here is what the actual program looks like when run inside Python Find out how a procedure can be used to hide the detail in your programs
Why should you use procedures when writing programs? Talk Task Why should you use procedures when writing programs? q1 – level 4 q2 + 3 – level 5 q4 + 5 – level 6 Find out how a procedure can be used to hide the detail in your programs
from turtle import * Using Standard libraries Learning development from turtle import * Using Standard libraries Python only has a limited number of built in methods (things it can do using single keywords like print) If you want to extend the number of choices of method you have to choose from you can use the from xxx import method at the beginning of your code. This example imports the screen turtle that I showed you in my example code Friday, 30 November 2018
Talk Task What is a library? How does using libraries improve your programming using Python? Why do you need to use functions when programming? What is the purpose of parameters? q1 – level 4 q2 + 3 – level 5 q4 + 5 – level 6 Find out how a procedure can be used to hide the detail in your programs
Independent Task Copy the code from page 9 to draw a triangle – can you adapt it so it is written as a procedure? Extend the program to use procedures to draw 3 different shapes. Upload to Edmodo once you are finished Find out how a procedure can be used to hide the detail in your programs
What is a procedure used for? Exit ticket What is a procedure used for? R A G scam Find out how a procedure can be used to hide the detail in your programs