Wednesday 7 January 2015

Python Evidence - Session 4 - Functions

 Using Python Basics - Level 1 
 Chapter 4 Functions - pg 45-54

Lesson Objectives

 - learn the structure of functions
 - write your own functions
 - create a program using functions




Starter
Try typing the following into Python Interactive mode;

Press Return twice, then type count(10) - What happens?  - see pg 46

Main
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.


 

 Use pg 46 to help you if you get stuck


~~~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:

 See pg 56



~~~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
Further reading:
 - http://learnpythonthehardway.org/book/ex19.html
 - http://usingpython.com/python-functions/

Homeowrk
Spend at leasst 30 minutes working on Code Academy - http://www.codecademy.com/learn

No comments:

Post a Comment