tracydani
06-15-2004, 09:11 PM
I am trying to learn something(hopefully) usefull from my time on the net.
But I cannot seem to get past this part(which is pretty much at the begginning of the training) and make it work.
I am using Python 2.3, the command module part and cannot do the following part:
___________________________________________________________________
The syntax for a function definition is:
def NAME( LIST OF PARAMETERS ):
STATEMENTS
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.
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.
The first couple of functions we are going to write have no parameters, so the syntax looks like this:
def newLine():
print
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.)
The syntax for calling the new function is the same as the syntax for built-in functions:
print "First Line."
newLine()
print "Second Line."
The output of this program is:
First line.
Second line.
Notice the extra space between the two lines. What if we wanted more space between the lines? We could call the same function repeatedly:
print "First Line."
newLine()
newLine()
newLine()
print "Second Line."
____________________________________________________________
Whenever I try to put in the commands such as:
def newLine():
print
and hit enter, then the commands
print "First Line."
newLine()
print "Second Line."
As soon as I hit enter after print "First Line." I get
File "<stdin>", line 2
print
IndentationError: expected an indented block
I cannot get it to perform the command it is supposed to.
Am I supposed to enter the whole command on one line with some sort of separator or something?
The instructions do not give any apparent reasons for this not to work.
Any help is appreciated.
TD
Also, the link to the instructions is here. (http://ibiblio.org/obp/thinkCS/python/english/chap03.htm)
But I cannot seem to get past this part(which is pretty much at the begginning of the training) and make it work.
I am using Python 2.3, the command module part and cannot do the following part:
___________________________________________________________________
The syntax for a function definition is:
def NAME( LIST OF PARAMETERS ):
STATEMENTS
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.
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.
The first couple of functions we are going to write have no parameters, so the syntax looks like this:
def newLine():
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.)
The syntax for calling the new function is the same as the syntax for built-in functions:
print "First Line."
newLine()
print "Second Line."
The output of this program is:
First line.
Second line.
Notice the extra space between the two lines. What if we wanted more space between the lines? We could call the same function repeatedly:
print "First Line."
newLine()
newLine()
newLine()
print "Second Line."
____________________________________________________________
Whenever I try to put in the commands such as:
def newLine():
and hit enter, then the commands
print "First Line."
newLine()
print "Second Line."
As soon as I hit enter after print "First Line." I get
File "<stdin>", line 2
IndentationError: expected an indented block
I cannot get it to perform the command it is supposed to.
Am I supposed to enter the whole command on one line with some sort of separator or something?
The instructions do not give any apparent reasons for this not to work.
Any help is appreciated.
TD
Also, the link to the instructions is here. (http://ibiblio.org/obp/thinkCS/python/english/chap03.htm)