The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
syntax error on compiling
Discuss syntax error on compiling in the Python Programming forum on Dev Shed. syntax error on compiling Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 15th, 2004, 10:13 PM
|
|
Registered User
|
|
Join Date: Feb 2004
Posts: 3
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
syntax error on compiling
hi ,
i am new to Linux and learning Python
I get a syntax error for this line of code
def fib(n): # write Fibonacci series up to n
i used Emacs as the editor on a Redhat ver8.0 OS.
any help is useful , thanks
--vissen
|

February 15th, 2004, 10:24 PM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
|
Please post the rest of your code too.
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne
|

February 15th, 2004, 10:40 PM
|
|
Registered User
|
|
Join Date: Feb 2004
Posts: 3
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
it is one of the examples given in the python tutorial by Guido Rossum which i used to learn. so here is the link
URL
please refer section 4.6 Defining Functions
i just copied this in emacs editor to check if it compiles when i got syntax error.
Code:
def fib(n): # write Fibonacci series up to n
"""Print a Fibonacci series up to n."""
a, b = 0, 1
while b < n:
print b,
a, b = b, a+b
Last edited by netytan : February 16th, 2004 at 05:55 AM.
|

February 15th, 2004, 10:42 PM
|
|
Registered User
|
|
Join Date: Feb 2004
Posts: 3
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
also tried this unsuccesfully
Code:
def fib2(n): # return Fibonacci series up to n
"""Return a list containing the Fibonacci series up to n."""
result = []
a, b = 0, 1
while b < n:
result.append(b) # see below
a, b = b, a+b
return result
-------
any ideas ??
Last edited by netytan : February 16th, 2004 at 06:00 AM.
|

February 15th, 2004, 10:54 PM
|
|
Contributing User
|
|
Join Date: Feb 2003
Location: Canada
|
|
Is your code properly indented, like in the example?
Code:
>>> def fib(n): # write Fibonacci series up to n
... """Print a Fibonacci series up to n."""
... a, b = 0, 1
... while b < n:
... print b,
... a, b = b, a+b
...
|

February 16th, 2004, 06:08 AM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
You're first example runs fine, no problem at all there. The second version is suffering from indentation arrors. if you insure that you're using 4 spaces for each indentation level it should work perfectly i.e.
Code:
def fib2(n):
"""Return a list containing the Fibonacci series up to n."""
result = []
a, b = 0, 1
while b < n:
result.append(b)
a, b = b, a + b
return result
print fib2(10)
Mark.
__________________
programming language development: www.netytan.com – Hula
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|