Python Basics Slides ÔÇô Ch4.1

Download Report

Transcript Python Basics Slides ÔÇô Ch4.1

[ slide 1 ]
Make a function
This is a starter activity and should take 5 minutes
1. Log in to your computer
2. Open IDLE
3. In interactive mode create this function:
>>> def count(number):
n=1
while n <= number:
print(n)
n = n+1
4. Press return untill the >>> prompt returns, then type this line:
>>> count(10)
[ slide 2 ]
Lesson Aims
In this lesson you are going to:
1. learn about functions
2. write your own functions
3. use your own functions
Vocabulary
function
def key word
argument
hacking
[ slide 3 ]
Interactive session
1. Read Delving deeper on page 47 – how to stop a code that will not finish.
2. Work your way through pages 47 – 50 in Python Basics.
Top Tip:
Do you remember how to copy chunks of code easily in IDLE?
If not, read what Mr Campbell has to say on page 50.
If you have finished:
1. Help other students who may be stuck
2.Try Idea 1 on page 53. Save your file in your Python Code folder.
[ slide 4 ]
Homework
1. Play the Light-Bot game here:
http://armorgames.com/play/2205/light-bot
2. Take a screen shot of where you got to in 30minutes and send it
to your teacher.
3. Stop if you have other homeworks to do!
[ slide 5 ]
Lesson Summary
In this lesson you have:
1. learn about functions
2. written your own functions
3. used your own functions
Vocabulary
You now know what a function is but what Python keyword is required?
What is an argument?
What does hacking mean?
def
Information required by a function
Re-writing bits of existing code to change
what it does