[Tutor] Function Problem 3.6
FrankBloeink at nerdshack.com
FrankBloeink at nerdshack.com
Thu Oct 14 11:05:39 CEST 2004
Hello Michael
Here's what I got when I read and tried the example you gave from the
book:
#defining the function (take care of indentation!)
>>> def newLine():
... print
...
#executing the function gives the ecpected output(a newline
# character, ie the cursor is jumping to the next line)
>>> newLine()
>>>
The problem with executing
print "First Line"
newLine()
print "Second Line"
in the python-shell is that every statement in the shell is directly
followed by the input, meaning you get a mixture of programm code and
output:
>>> print "First Line"
First Line
>>> nl()
>>> print "Second Line"
Second Line
>>>
If you would run this Program as a python script outside the
interpreter, you shoul get the expected result:
---start the script----
First Line
Second Line
---end of the output---
hth Frank
P.S: This is my first post to the list, although I've read on the list
for about 2 months. Thanks to all the members on the list for the
informative posts, I hope I can contibute myself from time to time, at
least at the more basic stuff for I'm only a Python-beginner, too.
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."
> 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.
>
> Michael
>
>
>
>
--
"(8) It is more complicated than you think."
RFC 1925: The Twelve Networking Truths
--
"(8) It is more complicated than you think."
RFC 1925: The Twelve Networking Truths
More information about the Tutor
mailing list