fiveperline.py


Below is the syntax highlighted version of fiveperline.py from §1.3 Conditionals and Loops.


#-----------------------------------------------------------------------
# fiveperline.py
#-----------------------------------------------------------------------

import stdio

# Write to standard output the integers from 1000 (inclusive) to 2000
# (exclusive), 5 integers per line.

START = 1000
END = 2000
INTS_PER_LINE = 5

for i in range(START, END):
    stdio.write(str(i) + ' ')
    if i % INTS_PER_LINE == INTS_PER_LINE - 1:
        stdio.writeln()
stdio.writeln()

#-----------------------------------------------------------------------

# python fiveperline.py        
# 1000 1001 1002 1003 1004 
# 1005 1006 1007 1008 1009 
# 1010 1011 1012 1013 1014 
# ...
# 1985 1986 1987 1988 1989 
# 1990 1991 1992 1993 1994 
# 1995 1996 1997 1998 1999


Copyright © 2000–2015, Robert Sedgewick, Kevin Wayne, and Robert Dondero.
Last updated: Fri Oct 20 20:45:16 EDT 2017.