Chapter 4 Functions - pg 45-54
Lesson Objectives
- learn the structure of functions
- write your own functions
- create a program using functions
Starter
Press Return twice, then type count(10) - What happens? - see pg 46
A function is a piece of code that performs a specific
task.
You already know some pre-built functions, such as print()
Red Task
Create a function that produces the times table. Remember to start by defining the function and giving an argument.
~~~Evidence~~~
1. Create a program that will print out the times table for any specified number
- print it, stick it in your book and write a note to explain the structure of the function
Orange Task
Make your program a little more complex by adding a second argument that will allow the user to decide how far through the tables to go:
~~~Evidence~~~
1. Write a program using a second argument
- print it, stick it in your book and write a note to explain why it is better than your first program today
Green Task
Copy out the code for the number guessing game on pg51.
Run it to check that it works.
ExtensionTry Ideas 1 to 4 on pg 53 - 54
Blog Post (to finish for hwk)
Add the following notes/code snippets to your blog entitled
'The structure of a function'
Plenary
Copy out the code for the number guessing game on pg51.
Run it to check that it works.
ExtensionTry Ideas 1 to 4 on pg 53 - 54
Blog Post (to finish for hwk)
Add the following notes/code snippets to your blog entitled
'The structure of a function'
Further reading:
- http://learnpythonthehardway.org/book/ex19.html
- http://usingpython.com/python-functions/
- http://learnpythonthehardway.org/book/ex19.html
- http://usingpython.com/python-functions/
Homeowrk
No comments:
Post a Comment