functions - Functions Institute for Personal Robots in...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 1 with Robots Functions Institute for Personal Robots in Education (IPRE)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Aug 29 2007 2 Functions A function is a piece of code you can use over and over again Treat it like a black box You pass it (optional) values, it does some work, and it (optionally) returns values You “call it”,”invoke it”, or “use it” by using its name and parentheses The things you pass it go inside the parentheses output = function( input ) function input output
Background image of page 2
Aug 29 2007 3 Using Simple Functions forward(1,1) beep(1, 440) Functions that interact with the robot forward (speed,duration) beep(time, frequency) Pass in arguments Execute in sequential order flow of execution
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Aug 29 2007 4 Writing Simple Functions def nudge (): print “going forward” forward(1,1) print “now stopped” nudge () Indent Defining functions Creates function Does not execute/run them Indenting indicates a “block” of code Call functions from top-level or other functions No Indention “Top Level”
Background image of page 4
Aug 29 2007 5 Format of a function definition def function-name(): statement statement statement
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Aug 29 2007 6 Writing Functions with Parameters def nudge ( speed ): print “Going forward with speed”, speed forward( speed ,1 ) print “stopped” stop() nudge ( 0.2 ) nudge ( 0.9 ) nudge ( 1 )
Background image of page 6
Aug 29 2007 7 Parameters are Variables When you pass values into functions as parameters, they
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/25/2012 for the course CS 1301 taught by Professor Staff during the Fall '08 term at Georgia Institute of Technology.

Page1 / 25

functions - Functions Institute for Personal Robots in...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online