Open in TheBrain

Python Warmup Practice Functions

<p>Jun 25, 2012 11:16 AM

&#160;

to get into &#160;function definiton editor, hit CONTROL N &#160;(for NEW)

&#160;

def hello(): &#160;&#160;&#160;&#160;&#160;&#160;&#160;note the colon after the arg list

&#160;&#160;&#160;&#160;print 'hello world' &#160;note the indentation before print; &#160;note, no punctuation to end it.

&#160;

then hit F5 to return to IDLE Interpreter

&#160;

*

&#160;

def sumo(n):

&#160;&#160;&#160;&#160;total=0

&#160;&#160;&#160;&#160;while i in range(1,n) : &#160;&#160;note that range generates the integer list from 1 THRU n-1 (ie n is NOT included)

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;total=total+i

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;print (i, total)

&#160;

*

def sean (a,b): &#160;&#160;note colon

&#160;&#160;&#160;&#160;c = ab &#160;&#160;&#160;&#160;a to the b; &#160;note &#160;only punctuation is the INDENT supplied automatically by IDLE.

&#160;&#160;&#160;&#160;print c &#160;&#160;&#160;&#160;hit F5 key to return to IDLE interpreter and then to run it by typing &#160;sean(3,5) for example</p>