1

Possible Duplicate:
Printing without newline (print 'a',) prints a space, how to remove?

I need to print the Fibonacci series Horizontally..ie., the output must be like this The Fibonacci series is : 0,1,1,2,3,5,8,13. I don't want to print it as a list also. I know how to print in vertically.. But can't print it horizontally with 'The Fibonacci series is : ' only coming once.. Please help guys!!

Community
  • 1
  • 1
Rejin Jose
  • 13
  • 3
  • See http://stackoverflow.com/questions/4499073/printing-without-newline-print-a-prints-a-space-how-to-remove and http://stackoverflow.com/questions/493386/how-to-print-in-python-without-newline-or-space – behnam Aug 20 '12 at 17:50

2 Answers2

1

I assume you want all the numbers in the series to be printed on the same line.

Your code would look like this

print 'The Fibonacci series is : ',
for i in xrange(1,10):
    #Calculate the next number 'n' to print
    print n,
Rajesh J Advani
  • 5,585
  • 2
  • 23
  • 35
-1

Working solution based on Rajesh answer.

a,b = 0,1
limit = 40
print 'The Fibonacci series is :', str(a), #str() necessary since 'print 0,' == ''
while(b < limit):
    print b,
    a,b = b,a+b

# output:
# The Fibonacci series is :  0,1,1,2,3,5,8,13,21,34
r4.
  • 358
  • 1
  • 6
  • 22