Algorithmic Approaches for Biological Data, Lecture #3 · 2019-12-01 · Algorithmic Approaches for...
Transcript of Algorithmic Approaches for Biological Data, Lecture #3 · 2019-12-01 · Algorithmic Approaches for...
Algorithmic Approaches for Biological Data, Lecture #3
Katherine St. John
City University of New YorkAmerican Museum of Natural History
27 January 2016
Outline
More on Functions
Simple Input
Program Design: top-down design, stepwise refinement
K. St. John (CUNY & AMNH) Algorithms #3 27 January 2016 2 / 7
Outline
More on Functions
Simple Input
Program Design: top-down design, stepwise refinement
K. St. John (CUNY & AMNH) Algorithms #3 27 January 2016 2 / 7
Outline
More on Functions
Simple Input
Program Design: top-down design, stepwise refinement
K. St. John (CUNY & AMNH) Algorithms #3 27 January 2016 2 / 7
Recap
Modules: turtles, random, math
Control structures: for
Built-in functions: print, range()
Design patterns: accumulator,input-process-output.
Overview of functions
K. St. John (CUNY & AMNH) Algorithms #3 27 January 2016 3 / 7
Recap
Modules: turtles, random, math
Control structures: for
Built-in functions: print, range()
Design patterns: accumulator,input-process-output.
Overview of functions
K. St. John (CUNY & AMNH) Algorithms #3 27 January 2016 3 / 7
Recap
Modules: turtles, random, math
Control structures: for
Built-in functions: print, range()
Design patterns: accumulator,input-process-output.
Overview of functions
K. St. John (CUNY & AMNH) Algorithms #3 27 January 2016 3 / 7
Recap
Modules: turtles, random, math
Control structures: for
Built-in functions: print, range()
Design patterns: accumulator,input-process-output.
Overview of functions
K. St. John (CUNY & AMNH) Algorithms #3 27 January 2016 3 / 7
Recap
Modules: turtles, random, math
Control structures: for
Built-in functions: print, range()
Design patterns: accumulator,input-process-output.
Overview of functions
K. St. John (CUNY & AMNH) Algorithms #3 27 January 2016 3 / 7
More on Functions
Standard form:
def myFunc(in1,in2,...):
command1command2...return(out1,out2,...)
Think CS function example (Alex theturtle drawing squares)
Parts of a function:
I Header: refers to the linebeginning with def that includesthe name and parameters
I Inputs: also called arguments orparameters
I Body: the commands inside thefunction
I Outputs: also called returnvalues
K. St. John (CUNY & AMNH) Algorithms #3 27 January 2016 4 / 7
More on Functions
Standard form:
def myFunc(in1,in2,...):
command1command2...return(out1,out2,...)
Think CS function example (Alex theturtle drawing squares)
Parts of a function:
I Header: refers to the linebeginning with def that includesthe name and parameters
I Inputs: also called arguments orparameters
I Body: the commands inside thefunction
I Outputs: also called returnvalues
K. St. John (CUNY & AMNH) Algorithms #3 27 January 2016 4 / 7
More on Functions
Standard form:
def myFunc(in1,in2,...):
command1command2...return(out1,out2,...)
Think CS function example (Alex theturtle drawing squares)
Parts of a function:
I Header: refers to the linebeginning with def that includesthe name and parameters
I Inputs: also called arguments orparameters
I Body: the commands inside thefunction
I Outputs: also called returnvalues
K. St. John (CUNY & AMNH) Algorithms #3 27 January 2016 4 / 7
More on Functions
Standard form:
def myFunc(in1,in2,...):
command1command2...return(out1,out2,...)
Think CS function example (Alex theturtle drawing squares)
Parts of a function:
I Header: refers to the linebeginning with def that includesthe name and parameters
I Inputs: also called arguments orparameters
I Body: the commands inside thefunction
I Outputs: also called returnvalues
K. St. John (CUNY & AMNH) Algorithms #3 27 January 2016 4 / 7
More on Functions
Standard form:
def myFunc(in1,in2,...):
command1command2...return(out1,out2,...)
Think CS function example (Alex theturtle drawing squares)
Parts of a function:
I Header: refers to the linebeginning with def that includesthe name and parameters
I Inputs: also called arguments orparameters
I Body: the commands inside thefunction
I Outputs: also called returnvalues
K. St. John (CUNY & AMNH) Algorithms #3 27 January 2016 4 / 7
More on Functions
Standard form:
def myFunc(in1,in2,...):
command1command2...return(out1,out2,...)
Think CS function example (Alex theturtle drawing squares)
Parts of a function:
I Header: refers to the linebeginning with def that includesthe name and parameters
I Inputs: also called arguments orparameters
I Body: the commands inside thefunction
I Outputs: also called returnvalues
K. St. John (CUNY & AMNH) Algorithms #3 27 January 2016 4 / 7
Local Variables
Standard form:
def myFunc(in1,in2,...):
command1command2...return(out1,out2,...)
Variables created inside a function,exist only in that function.
Any changes to local variables don’taffect variables outside the function.
Think CS demo (variables & localparameters)
Good style: only use values passed tothe function in calculations.
Any changes to local variables don’taffect variables outside the function.
K. St. John (CUNY & AMNH) Algorithms #3 27 January 2016 5 / 7
Local Variables
Standard form:
def myFunc(in1,in2,...):
command1command2...return(out1,out2,...)
Variables created inside a function,exist only in that function.
Any changes to local variables don’taffect variables outside the function.
Think CS demo (variables & localparameters)
Good style: only use values passed tothe function in calculations.
Any changes to local variables don’taffect variables outside the function.
K. St. John (CUNY & AMNH) Algorithms #3 27 January 2016 5 / 7
Local Variables
Standard form:
def myFunc(in1,in2,...):
command1command2...return(out1,out2,...)
Variables created inside a function,exist only in that function.
Any changes to local variables don’taffect variables outside the function.
Think CS demo (variables & localparameters)
Good style: only use values passed tothe function in calculations.
Any changes to local variables don’taffect variables outside the function.
K. St. John (CUNY & AMNH) Algorithms #3 27 January 2016 5 / 7
Local Variables
Standard form:
def myFunc(in1,in2,...):
command1command2...return(out1,out2,...)
Variables created inside a function,exist only in that function.
Any changes to local variables don’taffect variables outside the function.
Think CS demo (variables & localparameters)
Good style: only use values passed tothe function in calculations.
Any changes to local variables don’taffect variables outside the function.
K. St. John (CUNY & AMNH) Algorithms #3 27 January 2016 5 / 7
Functions calling Functions
Functions can call other functions.
Think CS demo
Group Work: Think CS, Flow of ExecutionSummary Questions
K. St. John (CUNY & AMNH) Algorithms #3 27 January 2016 6 / 7
Functions calling Functions
Functions can call other functions.
Think CS demo
Group Work: Think CS, Flow of ExecutionSummary Questions
K. St. John (CUNY & AMNH) Algorithms #3 27 January 2016 6 / 7
Functions calling Functions
Functions can call other functions.
Think CS demo
Group Work: Think CS, Flow of ExecutionSummary Questions
K. St. John (CUNY & AMNH) Algorithms #3 27 January 2016 6 / 7
Recap
Lab at 3pm.
Email lab reports to [email protected]
Challenges available at rosalind.info(use emailed link to access course page).
K. St. John (CUNY & AMNH) Algorithms #3 27 January 2016 7 / 7
Recap
Lab at 3pm.
Email lab reports to [email protected]
Challenges available at rosalind.info(use emailed link to access course page).
K. St. John (CUNY & AMNH) Algorithms #3 27 January 2016 7 / 7
Recap
Lab at 3pm.
Email lab reports to [email protected]
Challenges available at rosalind.info(use emailed link to access course page).
K. St. John (CUNY & AMNH) Algorithms #3 27 January 2016 7 / 7