Top Banner
Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution Lice See http://software-carpentry.org/license.html for more informati Python
87

Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Dec 29, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Functions

Copyright © Software Carpentry 2010

This work is licensed under the Creative Commons Attribution License

See http://software-carpentry.org/license.html for more information.

Python

Page 2: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

A programming language should not include

everything anyone might ever want

Page 3: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

A programming language should not include

everything anyone might ever want

Instead, it should make it easy for people to create

what they need to solve specific problems

Page 4: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

A programming language should not include

everything anyone might ever want

Instead, it should make it easy for people to create

what they need to solve specific problems

Define functions to create higher-level operations

Page 5: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

A programming language should not include

everything anyone might ever want

Instead, it should make it easy for people to create

what they need to solve specific problems

Define functions to create higher-level operations

"Create a language in which the solution to your

original problem is trivial."

Page 6: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Define functions using def

Page 7: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Define functions using def

def greet(): return 'Good evening, master'

Page 8: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Define functions using def

def greet(): return 'Good evening, master'

temp = greet()print tempGood evening, master

Page 9: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Give them parameters

Page 10: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Give them parameters

def greet(name): answer = 'Hello, ' + name return answer

Page 11: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Give them parameters

stack value

temp

'doctor'

def greet(name): answer = 'Hello, ' + name return answer

temp = 'doctor'

Page 12: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Give them parameters

stack value

temp

'doctor'

name

def greet(name): answer = 'Hello, ' + name return answer

temp = 'doctor'result = greet(temp)

Page 13: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Give them parameters

stack value

temp

'doctor'

'Hello, doctor'

name

answer

def greet(name): answer = 'Hello, ' + name return answer

temp = 'doctor'result = greet(temp)

Page 14: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Give them parameters

stack value

temp

result

'doctor'

'Hello, doctor'

def greet(name): answer = 'Hello, ' + name return answer

temp = 'doctor'result = greet(temp)

Page 15: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Each function call creates a new stack frame

Page 16: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Each function call creates a new stack frame

def add(a): b = a + 1 return b

def double(c): d = 2 * add(c) return d

stack value

Page 17: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Each function call creates a new stack frame

def add(a): b = a + 1 return b

def double(c): d = 2 * add(c) return d

val = 10

stack value

10

val

Page 18: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Each function call creates a new stack frame

def add(a): b = a + 1 return b

def double(c): d = 2 * add(c) return d

val = 10result = double(val)

stack value

10

c

valdouble

Page 19: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Each function call creates a new stack frame

def add(a): b = a + 1 return b

def double(c): d = 2 * add(c) return d

val = 10result = double(val)

stack value

10a

c

valdouble

add

Page 20: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Each function call creates a new stack frame

def add(a): b = a + 1 return b

def double(c): d = 2 * add(c) return d

val = 10result = double(val)print result stack value

10

11

ab

c

valresult

double

add

Page 21: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Each function call creates a new stack frame

def add(a): b = a + 1 return b

def double(c): d = 2 * add(c) return d

val = 10result = double(val)print result stack value

10

22

cd

valresult

double

Page 22: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Each function call creates a new stack frame

def add(a): b = a + 1 return b

def double(c): d = 2 * add(c) return d

val = 10result = double(val)print result stack value

10

22valresult

Page 23: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Each function call creates a new stack frame

def add(a): b = a + 1 return b

def double(c): d = 2 * add(c) return d

val = 10result = double(val)print result22

stack value

10

22valresult

Page 24: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Only see variables in the current and global frames

Page 25: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Only see variables in the current and global frames

Current beats global

Page 26: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Only see variables in the current and global frames

Current beats global

def greet(name): temp = 'Hello, ' + name return temp

temp = 'doctor'result = greet(temp)

Page 27: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Only see variables in the current and global frames

Current beats global

def greet(name): temp = 'Hello, ' + name return temp

temp = 'doctor'result = greet(temp)

stack value

temp

'Hello, doctor'

'doctor'global

greet

name

temp

Page 28: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Only see variables in the current and global frames

Current beats global

def greet(name): temp = 'Hello, ' + name return temp

temp = 'doctor'result = greet(temp)print resultHello, doctor

stack value

temp

result

'Hello, doctor'

'doctor'global

Page 29: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Can pass values in and accept results directly

Page 30: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Can pass values in and accept results directly

def greet(name): return 'Hello, ' + name

print greet('doctor')

Page 31: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Can pass values in and accept results directly

def greet(name): return 'Hello, ' + name

print greet('doctor')

stack value

_x1_

'doctor'

'Hello, doctor'

name

_x2_

Page 32: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Can return at any time

Page 33: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Can return at any time

def sign(num): if num > 0: return 1 elif num == 0: return 0 else: return -1

Page 34: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Can return at any time

def sign(num): if num > 0: return 1 elif num == 0: return 0 else: return -1

print sign(3)1

Page 35: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Can return at any time

def sign(num): if num > 0: return 1 elif num == 0: return 0 else: return -1

print sign(3)1print sign(-9)-1

Page 36: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Can return at any time

def sign(num): if num > 0: return 1 elif num == 0: return 0 else: return -1

print sign(3)1print sign(-9)-1

Over-use makes functions

hard to understand

Page 37: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Can return at any time

def sign(num): if num > 0: return 1 elif num == 0: return 0 else: return -1

print sign(3)1print sign(-9)-1

Over-use makes functions

hard to understand

No prescription possible, but:

Page 38: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Can return at any time

def sign(num): if num > 0: return 1 elif num == 0: return 0 else: return -1

print sign(3)1print sign(-9)-1

Over-use makes functions

hard to understand

No prescription possible, but:

– a few at the beginning

to handle special cases

Page 39: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Can return at any time

def sign(num): if num > 0: return 1 elif num == 0: return 0 else: return -1

print sign(3)1print sign(-9)-1

Over-use makes functions

hard to understand

No prescription possible, but:

– a few at the beginning

to handle special cases

– one at the end for the

"general" result

Page 40: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Every function returns something

Page 41: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Every function returns something

def sign(num): if num > 0: return 1 elif num == 0: return 0# else:# return -1

Page 42: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Every function returns something

def sign(num): if num > 0: return 1 elif num == 0: return 0# else:# return -1

print sign(3)1

Page 43: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Every function returns something

def sign(num): if num > 0: return 1 elif num == 0: return 0# else:# return -1

print sign(3)1print sign(-9)None

Page 44: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Every function returns something

def sign(num): if num > 0: return 1 elif num == 0: return 0# else:# return -1

print sign(3)1print sign(-9)None

If the function doesn't return

a value, Python returns None

Page 45: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Every function returns something

def sign(num): if num > 0: return 1 elif num == 0: return 0# else:# return -1

print sign(3)1print sign(-9)None

If the function doesn't return

a value, Python returns None

Yet another reason why

commenting out blocks of code

is a bad idea...

Page 46: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Functions and parameters don't have types

Page 47: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Functions and parameters don't have types

def double(x): return 2 * x

Page 48: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Functions and parameters don't have types

def double(x): return 2 * x

print double(2)4

Page 49: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Functions and parameters don't have types

def double(x): return 2 * x

print double(2)4print double('two')twotwo

Page 50: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Functions and parameters don't have types

def double(x): return 2 * x

print double(2)4print double('two')twotwo

Only use this when the

function's behavior depends

only on properties that all

possible arguments share

Page 51: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Functions and parameters don't have types

def double(x): return 2 * x

print double(2)4print double('two')twotwo

Only use this when the

function's behavior depends

only on properties that all

possible arguments share

if type(arg) == int: ...elif type(arg) == str: ......

Page 52: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Functions and parameters don't have types

def double(x): return 2 * x

print double(2)4print double('two')twotwo

Only use this when the

function's behavior depends

only on properties that all

possible arguments share

Warning sign if type(arg) == int: ...elif type(arg) == str: ......

Page 53: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Functions and parameters don't have types

def double(x): return 2 * x

print double(2)4print double('two')twotwo

Only use this when the

function's behavior depends

only on properties that all

possible arguments share

Warning sign

There's a better

way to do this

if type(arg) == int: ...elif type(arg) == str: ......

Page 54: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Values are copied into parameters

Page 55: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Values are copied into parameters

Which means lists are aliased

Page 56: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Values are copied into parameters

Which means lists are aliased

def appender(a_string, a_list): a_string += 'turing' a_list.append('turing')

Page 57: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Values are copied into parameters

Which means lists are aliased

def appender(a_string, a_list): a_string += 'turing' a_list.append('turing')

string_val = 'alan'list_val = ['alan']appender(string_val, list_val)

Page 58: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Values are copied into parameters

Which means lists are aliased

def appender(a_string, a_list): a_string += 'turing' a_list.append('turing')

string_val = 'alan'list_val = ['alan']appender(string_val, list_val)

stack value

string_val

list_val

'alan'

['alan']

Page 59: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Values are copied into parameters

Which means lists are aliased

def appender(a_string, a_list): a_string += 'turing' a_list.append('turing')

string_val = 'alan'list_val = ['alan']appender(string_val, list_val)

stack value

string_val

list_val

'alan'

['alan']

a_string

a_list

Page 60: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Values are copied into parameters

Which means lists are aliased

def appender(a_string, a_list): a_string += 'turing' a_list.append('turing')

string_val = 'alan'list_val = ['alan']appender(string_val, list_val)

stack value

string_val

list_val

'alan'

'alanturing'

['alan']

a_string

a_list

Page 61: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Values are copied into parameters

Which means lists are aliased

def appender(a_string, a_list): a_string += 'turing' a_list.append('turing')

string_val = 'alan'list_val = ['alan']appender(string_val, list_val)

stack value

string_val

list_val

'alan'

'alanturing'

['alan', 'turing']

a_string

a_list

Page 62: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Values are copied into parameters

Which means lists are aliased

def appender(a_string, a_list): a_string += 'turing' a_list.append('turing')

string_val = 'alan'list_val = ['alan']appender(string_val, list_val)print string_valalanprint list_val['alan', 'turing']

stack value

string_val

list_val

'alan'

['alan', 'turing']

Page 63: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Can define default parameter values

Page 64: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Can define default parameter values

def adjust(value, amount=2.0): return value * amount

Page 65: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Can define default parameter values

def adjust(value, amount=2.0): return value * amount

print adjust(5)10

Page 66: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Can define default parameter values

def adjust(value, amount=2.0): return value * amount

print adjust(5)10print adjust(5, 1.001)5.005

Page 67: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

More readable than multiple functions

Page 68: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

More readable than multiple functions

def adjust_general(value, amount): return value * amount

def adjust_default(value): return adjust_general(value, 2.0)

Page 69: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Parameters that have defaults must come after

parameters that do not

Page 70: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Parameters that have defaults must come after

parameters that do not

def triplet(left='venus', middle, right='mars'): return '%s %s %s' % (left, middle, right)

Page 71: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Parameters that have defaults must come after

parameters that do not

def triplet(left='venus', middle, right='mars'): return '%s %s %s' % (left, middle, right)

print triplet('earth')venus earth mars

OK so far...

Page 72: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Parameters that have defaults must come after

parameters that do not

def triplet(left='venus', middle, right='mars'): return '%s %s %s' % (left, middle, right)

print triplet('earth')venus earth mars

print triplet('pluto', 'earth')

OK so far...

?

Page 73: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Parameters that have defaults must come after

parameters that do not

def triplet(left='venus', middle, right='mars'): return '%s %s %s' % (left, middle, right)

print triplet('earth')venus earth mars

print triplet('pluto', 'earth')

OK so far...

triplet('pluto', 'earth', 'mars')

?

Page 74: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Parameters that have defaults must come after

parameters that do not

def triplet(left='venus', middle, right='mars'): return '%s %s %s' % (left, middle, right)

print triplet('earth')venus earth mars

print triplet('pluto', 'earth')

OK so far...

triplet('venus', 'pluto', 'earth')

triplet('pluto', 'earth', 'mars')

?

Page 75: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

"When should I write a function?"

Page 76: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

"When should I write a function?"

Human short term memory can hold 7± 2 items

Page 77: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

"When should I write a function?"

Human short term memory can hold 7± 2 items

If someone has to keep more than a dozen things

in their mind at once to understand a block of code,

it's too long

Page 78: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

"When should I write a function?"

Human short term memory can hold 7± 2 items

If someone has to keep more than a dozen things

in their mind at once to understand a block of code,

it's too long

Break it into comprehensible pieces with functions

Page 79: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

"When should I write a function?"

Human short term memory can hold 7± 2 items

If someone has to keep more than a dozen things

in their mind at once to understand a block of code,

it's too long

Break it into comprehensible pieces with functions

Even if each function is only called once

Page 80: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Example

for x in range(1, GRID_WIDTH-1): for y in range(1, GRID_HEIGHT-1): if (density[x-1][y] > density_threshold) or \ (density[x+1][y] > density_threshold): if (flow[x][y-1] < flow_threshold) or\ (flow[x][y+1] < flow_threshold): temp = (density[x-1][y] + density[x+1][y]) / 2 if abs(temp - density[x][y]) > update_threshold: density[x][y] = temp

Page 81: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Refactoring #1: grid interior

for x in grid_interior(GRID_WIDTH): for y in grid_interior(GRID_HEIGHT): if (density[x-1][y] > density_threshold) or \ (density[x+1][y] > density_threshold): if (flow[x][y-1] < flow_threshold) or\ (flow[x][y+1] < flow_threshold): temp = (density[x-1][y] + density[x+1][y]) / 2 if abs(temp - density[x][y]) > update_threshold: density[x][y] = temp

Page 82: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Refactoring #2: tests on X and Y axes

for x in grid_interior(GRID_WIDTH): for y in grid_interior(GRID_HEIGHT): if density_exceeds(density, x, y, density_threshold): if flow_exceeds(flow, x, y, flow_threshold): temp = (density[x-1][y] + density[x+1][y]) / 2 if abs(temp - density[x][y]) > tolerance: density[x][y] = temp

Page 83: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Refactoring #3: update rule

for x in grid_interior(GRID_WIDTH): for y in grid_interior(GRID_HEIGHT): if density_exceeds(density, x, y, density_threshold): if flow_exceeds(flow, x, y, flow_threshold): update_on_tolerance(density, x, y, tolerance)

Page 84: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Refactoring #3: update rule

for x in grid_interior(GRID_WIDTH): for y in grid_interior(GRID_HEIGHT): if density_exceeds(density, x, y, density_threshold): if flow_exceeds(flow, x, y, flow_threshold): update_on_tolerance(density, x, y, tolerance)

Good programmers will write this first

Page 85: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Refactoring #3: update rule

Good programmers will write this first

Then write the functions it implies

for x in grid_interior(GRID_WIDTH): for y in grid_interior(GRID_HEIGHT): if density_exceeds(density, x, y, density_threshold): if flow_exceeds(flow, x, y, flow_threshold): update_on_tolerance(density, x, y, tolerance)

Page 86: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Python Functions

Refactoring #3: update rule

Good programmers will write this first

Then write the functions it implies

Then refactor any overlap

for x in grid_interior(GRID_WIDTH): for y in grid_interior(GRID_HEIGHT): if density_exceeds(density, x, y, density_threshold): if flow_exceeds(flow, x, y, flow_threshold): update_on_tolerance(density, x, y, tolerance)

Page 87: Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

October 2010

created by

Greg Wilson

Copyright © Software Carpentry 2010

This work is licensed under the Creative Commons Attribution License

See http://software-carpentry.org/license.html for more information.