L. Kappa L. Kappa - 1 month ago 6
Python Question

Allignment hoirzontal instead of vertical

I'm working on an assignment for school and we're supposed to make a script that counts to 100 in blocks of 10. So you would get number 1 to 10 in row 1, from left to right. In row 2 you'd get 10-20, from left to right, and so on.

I've wrote some part of the script but I can't figure out how to allign it from left to right, instead of top to bottom. This is what I've got so far:

def number(count):
while count!=11:
print(count)
count=count+1;
number(0)

Answer

You can use sys.stdout.write, or print() specifying end

import sys

def number(count):
    while count!=11:
        sys.stdout.write('{0}\t'.format(count))
        #OR
        print(count,end=' ')

        count=count+1;
number(0)
Comments