0

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)
Cœur
  • 37,241
  • 25
  • 195
  • 267
L. Kappa
  • 25
  • 2
  • 6

3 Answers3

0
import numpy as np

 numpy.arange(100)
 numpy.arange(100).reshape(10,10)

The above code should work fine.

1111
  • 93
  • 1
  • 1
  • 11
  • Adding `numpy` as a dependency is probably not what OP's professor had in mind. Especially since this can be done without any imports. – kylieCatt Oct 15 '16 at 23:25
0

You could 'build-up' the string an then print the result. This may not be the best solution if you have a long string to print out, but for ten numbers at a time it would work.

For example:

some_string = ''
for i in range(1, 11):
    some_string += str(i)
print(some_string)

Following this idea, you could extend it to printing the rest of the numbers.

Just for kicks I'll also add that you COULD use list comprehensions in some way.

As an example: ', '.join([str(x) for x in range(1, 11)])

kylieCatt
  • 10,672
  • 5
  • 43
  • 51
rufism
  • 382
  • 1
  • 9
0

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)
R. S. Nikhil Krishna
  • 3,962
  • 1
  • 13
  • 27