Download presentation
Presentation is loading. Please wait.
1
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
2
Sub-solution using procedures
3
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
4
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
5
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
6
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
7
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
8
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
9
New Learning def square(): forward(100) right(90)
Find out how a procedure can be used to hide the detail in your programs
10
New Learning def square(): forward(100) right(90)
Find out how a procedure can be used to hide the detail in your programs
11
New Learning def square(): forward(100) right(90)
Find out how a procedure can be used to hide the detail in your programs
12
New Learning def square(): forward(100) right(90)
Find out how a procedure can be used to hide the detail in your programs
13
New Learning def square(): forward(100) right(90)
Find out how a procedure can be used to hide the detail in your programs
14
New Learning def square(): forward(100) right(90)
Find out how a procedure can be used to hide the detail in your programs
15
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
16
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
17
New Learning square() right(70) forward(100)
Find out how a procedure can be used to hide the detail in your programs
18
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
19
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
20
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
21
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
22
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
23
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
24
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
25
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
26
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
27
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
28
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
29
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
30
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
31
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
32
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.