tutorial example?????

Brian van den Broek broek at cc.umanitoba.ca
Sun Nov 13 06:03:06 EST 2005


john boy said unto the world upon 2005-11-12 19:43:
> OK...I have the following program
>  
> i = 1
> while i <= 6:
>     print 2 * i,'   ',
>     i = i + 1
> print
>  
> this is supposed to give you a "new" blank line after the program runs instead it just gives:
> 2   4   6   8   10   12
> 
>  
> instead of:
> 2   4   6   8   10   12
>  
> 
>  
> to get the above return I have to type in "print" twice,this can't be right?..ANY SUGGESTIONS?
>  
> i = 1while i <= 6:
>     print 2 * i,'   ',
>     i = i + 1
> print
> print


IDLE 1.1.2
 >>> def as_excepted():
	print "The trailing comma makes the next print be ",
	print "on the same line as this one"

	
 >>> as_excepted()
The trailing comma makes the next print be  on the same line as this one
 >>>


Try putting a string behind the print statement that appears not to be 
doing anything, and you will see that it is. The first print is needed 
to clear out of the looped print's comma.

If you don't like the repetition, you could:


 >>> def one_way():
	for i in range(3):
		print i,
	print '\n'   # Explicitly request newline

	
 >>> one_way()
0 1 2

 >>>

Best,

Brian vdB




More information about the Python-list mailing list