LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-05-2014, 03:43 AM   #1
sryzdn
Member
 
Registered: Feb 2013
Posts: 266

Rep: Reputation: 9
python function definition


Hi,

I have just started learning python. This is the error I am receiving:
Code:
>>> def add(a, b) :
... return a + b
  File "<stdin>", line 2
    return a + b
         ^
IndentationError: expected an indented block
This is while the book I am reading has just mentioned. Please kindly let me know the correct indentation.
 
Old 04-05-2014, 03:51 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,496

Rep: Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867
What do you not understand? The error is VERY specific on what the problem is.
 
Old 04-05-2014, 04:18 AM   #3
sryzdn
Member
 
Registered: Feb 2013
Posts: 266

Original Poster
Rep: Reputation: 9
Quote:
Originally Posted by grail View Post
What do you not understand? The error is VERY specific on what the problem is.
I know that my indentation is wrong. But, I don't know how to correct it.
 
Old 04-05-2014, 05:02 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,496

Rep: Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867
Looking at your example you have zero indentation. Try adding a space or tab and see what happens? Is your book online? I find it hard to believe it has not shown you an example
of a function definition?
 
Old 04-05-2014, 05:09 AM   #5
sryzdn
Member
 
Registered: Feb 2013
Posts: 266

Original Poster
Rep: Reputation: 9
Quote:
Originally Posted by grail View Post
Looking at your example you have zero indentation. Try adding a space or tab and see what happens? Is your book online? I find it hard to believe it has not shown you an example
of a function definition?
The book is "introduction to python prgramming" by nclab.
I have checked all the possible spaces and tabs and parentheses, but still the error remains.
 
Old 04-05-2014, 05:13 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,496

Rep: Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867
Well I am not sure how far you looked into this issue. By using google and a search criteria of "python how to define a function", of the 5 million+ results the first seems quite informative:

http://anh.cs.luc.edu/python/hands-o...functions.html
 
Old 04-05-2014, 05:45 AM   #7
sryzdn
Member
 
Registered: Feb 2013
Posts: 266

Original Poster
Rep: Reputation: 9
Quote:
Originally Posted by grail View Post
Well I am not sure how far you looked into this issue. By using google and a search criteria of "python how to define a function", of the 5 million+ results the first seems quite informative:

http://anh.cs.luc.edu/python/hands-o...functions.html
The results of the example of the link you have mentioned, exactly copied and pasted:

Code:
>>> def sumProblem(x, y):
... sum = x + y
  File "<stdin>", line 2
    sum = x + y
      ^
IndentationError: expected an indented block
 
Old 04-05-2014, 06:06 AM   #8
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,496

Rep: Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867
Exactly you say.... hmmmm:
Code:
>>> def sumProblem(x, y):
...     sum = x + y
... 
>>>
This is exactly what happens when I paste from the same page and then hit the enter key after the last lot of '...'

Why is it your paste does not look the same??
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Where is Socket function definition? Niranjan.S Linux - Kernel 2 12-30-2011 03:00 PM
function definition for pcbios_read_config_dword() giri_blr Linux - Kernel 0 07-03-2008 11:41 PM
bind function definition prabhakar_kushwaha Linux - General 1 08-07-2007 08:39 PM
Using __THROW in function definition drimades Programming 1 11-15-2006 05:50 AM
function definition query slzckboy Programming 1 04-18-2006 08:29 AM


All times are GMT -5. The time now is 10:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration