Python Forum

Full Version: function definition (pycharm)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Ok so i´m new to coding and have ZERO experience in this...I am reading a book i found online and i am trying to do some of the activties that are shown in the book. I am using pycharm to test my coding. The code i am writing is as follows.


>>> def print_lyrics():
... print "lumber jacks"
... print "im a sleep"
...

File "<input>", line 2
print "lumber jacks"
^
SyntaxError: Missing parentheses in call to 'print'



The book says "to end the function, you have to enter an empty line ( this is not necessary in a script)."

I understand that the three dots means that the definition is not complete...so how do i complete the freakin thing???
I just want to define lyrics as lumberjacks and im a sleep, right...thats what im trying to do??

This has got to be a simple misunderstanding...

Link of book >>> http://www.greenteapress.com/thinkpython...hap01.html

Im on chapter 3 functions 3.5 section

thank you for reading and hope that made sense.
i bet youre using the python 2 version of thinkpython.

as the page says, you probably want this: http://greenteapress.com/wp/think-python-2e/

also: print("lumber jacks")
Originally, python would cause an assertion error if the code did not end in newline. (see https://pypi.python.org/pypi/pep8/1.7.1) 1.4, 3rd item
this was corrected  PEP8 issue #119 and is no longer required.
It's probably left over in PyCharm from this old issue.

I always end code with a newline, not because it's required, but that I don't personally feel it's complete without it.
I figured out the problem with your guys posts! thank you two very much!