<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1458" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><!--StartFragment --><!--StartFragment --><FONT
face="Verdana, Arial, Helvetica"><FONT face="Verdana, Arial, Helvetica"
size=2><SPAN class=spnMessageText id=msg>This is my first post, so HI all! and
thank you for you help!</SPAN></FONT></FONT></DIV>
<DIV><FONT face="Verdana, Arial, Helvetica"><FONT
face="Verdana, Arial, Helvetica" size=2><SPAN
class=spnMessageText></SPAN></FONT></FONT> </DIV>
<DIV><FONT face="Verdana, Arial, Helvetica"><FONT
face="Verdana, Arial, Helvetica" size=2><SPAN class=spnMessageText>Below is a
tutorial that I am trying to complete, but I can not duplicate this exercise in
either the IDLE gui or command line. (ver 2.3.4)<BR>Tutorial says do
this</SPAN></FONT></FONT></DIV>
<DIV><FONT face="Verdana, Arial, Helvetica"><FONT
face="Verdana, Arial, Helvetica" size=2><SPAN
class=spnMessageText></SPAN></FONT></FONT> </DIV>
<DIV><FONT face="Verdana, Arial, Helvetica"><FONT
face="Verdana, Arial, Helvetica" size=2><SPAN class=spnMessageText><SPAN
class=spnMessageText id=msg>go to IDLE gui and define the new
function</SPAN></SPAN></FONT></FONT></DIV>
<DIV><FONT face="Verdana, Arial, Helvetica"><FONT
face="Verdana, Arial, Helvetica" size=2><SPAN class=spnMessageText><SPAN
class=spnMessageText><BR><FONT color=#0000ff>def
newLine():<BR> print</FONT><BR></SPAN></DIV>
<DIV><FONT face=Arial></FONT>then i open another IDLE window and write the
3 line program like in the tutorial <BR><BR><FONT color=#0000ff>print "First
Line."<BR>newLine()<BR>print "Second Line."</FONT><BR><BR>save it as
line.py<BR><BR>Now I am to see this output result upon running it <BR><BR><FONT
color=#0000ff>First line.<BR><BR>Second line</FONT>. <BR><BR>But I dont get
this, I get a First line." printed and a syntax error<BR><BR>>>>
<BR><FONT color=#0000ff>First Line.</FONT><BR><BR><FONT color=#ff0000>Traceback
(most recent call last):<BR>File "C:/Python23/newLine.py", line 2, in
-toplevel-<BR>newLine()<BR>NameError: name 'newLine' is not
defined</FONT><BR>>>> <BR><BR><BR>complete lesson below
<BR><BR></SPAN></FONT></FONT><FONT face="Verdana, Arial, Helvetica"><FONT
face="Verdana, Arial, Helvetica" size=2><SPAN class=spnMessageText
id=msg><BR>3.6 Adding new functions<BR><BR>So far, we have only been using the
functions that come with Python, but it is also possible to add new functions.
Creating new functions to solve your particular problems is one of the most
useful things about a general-purpose programming language.<BR><BR>In the
context of programming, a function is a named sequence of statements that
performs a desired operation. This operation is specified in a function
definition. The functions we have been using so far have been defined for us,
and these definitions have been hidden. This is a good thing, because it allows
us to use the functions without worrying about the details of their
definitions.<BR><BR>The syntax for a function definition is:<BR><BR>def NAME(
LIST OF PARAMETERS ):<BR>STATEMENTS<BR><BR>You can make up any names you want
for the functions you create, except that you can't use a name that is a Python
keyword. The list of parameters specifies what information, if any, you have to
provide in order to use the new function.<BR><BR>There can be any number of
statements inside the function, but they have to be indented from the left
margin. In the examples in this book, we will use an indentation of two
spaces.<BR><BR>The first couple of functions we are going to write have no
parameters, so the syntax looks like this:<BR><BR>def
newLine():<BR>print<BR><BR>This function is named newLine. The empty parentheses
indicate that it has no parameters. It contains only a single statement, which
outputs a newline character. (That's what happens when you use a printcommand
without any arguments.)<BR><BR>The syntax for calling the new function is the
same as the syntax for built-in functions:<BR><BR>print "First
Line."<BR>newLine()<BR>print "Second Line."<BR><BR>The output of this program
is:<BR><BR>First line.<BR><BR>Second line.<BR><BR>Notice the extra space between
the two lines. What if we wanted more space between the lines? We could call the
same function repeatedly:<BR><BR>print "First
Line."<BR>newLine()<BR>newLine()<BR>newLine()<BR>print "Second Line."<BR><BR>Or
we could write a new function named threeLines that prints three new
lines:<BR><BR>def
threeLines():<BR>newLine()<BR>newLine()<BR>newLine()<BR><BR>print "First
Line."<BR>threeLines()<BR>print "Second Line."<BR><BR>This function contains
three statements, all of which are indented by two spaces. Since the next
statement is not indented, Python knows that it is not part of the
function.<BR><BR>You should notice a few things about this program:<BR><BR>1.
You can call the same procedure repeatedly. In fact, it is quite common and
useful to do so.<BR>2. You can have one function call another function; in this
case threeLines calls newLine.<BR><BR>So far, it may not be clear why it is
worth the trouble to create all of these new functions. Actually, there are a
lot of reasons, but this example demonstrates two:<BR><BR>* Creating a new
function gives you an opportunity to name a group of statements. Functions can
simplify a program by hiding a complex computation behind a single command and
by using English words in place of arcane code.<BR>* Creating a new function can
make a program smaller by eliminating repetitive code. For example, a short way
to print nine consecutive new lines is to call threeLines three times.<BR><BR>As
an exercise, write a function called nineLines that uses threeLines to print
nine blank lines. How would you print twenty-seven new lines?
<BR></DIV></SPAN></FONT></FONT></BODY></HTML>