[Tutor] Function Problem 3.6

Bill Mill bill.mill at gmail.com
Thu Oct 14 08:21:46 CEST 2004


Mike,

any statement which is in a Python block needs to be indented. Blocks
include such things as functions and loops; here you are trying to
enter a function.

So, here's the code we're shooting for:

def newLine():
    print

To enter this into the interpreter, enther the first line and press
enter. When the ellipses appear, press tab, then enter print and hit
enter. The IndentationError you were getting was caused by the print
statement not being indented.

At this point, you have *defined* a function, but now you can try
calling it. To do so, you do this:

>>>newLine()

And hit enter; a blank line will be printed.

Hope this helped.

Peace
Bill Mill
bill.mill at gmail.com


On Thu, 14 Oct 2004 00:59:18 -0400, Comcast Mail <cgjung at comcast.net> wrote:
>  
>  
> 
> The exercise below refers to section 3.6 in "How to think like a computer
> scientist: Learning with Python."  I have version 2.3.4 of Python. I've
> copied part of it between the brackets below. 
> 
> [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 print command without any
> arguments.) ] 
> 
> My problem is that when I attempt the exercise above, I get the following: 
> 
>   
> 
> >>>def  newLine():    I then hit "enter" key,  and I get 
> 
>> 
>   
> 
> I get three ellipses, no "print" output.  If I then enter 
> 
> >>>print "First Line." 
> 
>   
> 
> Instead of getting the output "newLine()" as the book states 
> 
>   
> 
> I get an "indentationerror." 
> 
>   
> 
> Obviously the >>>print "Second Line."  Doesn't work either. 
> 
>   
> 
>   
> 
>   
> 
> I hope I've explained this well enough. What the heck is going on?   I had
> no problems with earlier exercises. Any help would be greatly appreciated. 
> Please respond both on the board and to me at this email address if
> possible. 
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
> 
> 
>   
> 
> 
> Michael 
> 
>   
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 
>


More information about the Tutor mailing list