jeudi 5 octobre 2017

Line up numbers in multiple lines

world!

I'm stuck at a basic question. We're using simple commands for these questions (format, if, while, and all basics).

I came as far as to be able to produce this:

  1  2  3  4
  1  2  3  4
  1  2  3  4
  1  2  3  4

by using the following code:

number= 0
while number<= 0:
    number = input("Give a number which is bigger than 0 : ")
    if number.isdigit():
        number=int(number)
    else:
        print("Give an integer")
        number= 0
for x in range(number):
    for y in range(1,number+1):
        print(" {}{} ".format('',y), end='' )
    print('')

The problem comes with the next question:

  1  2  3  4
  5  6  7  8
  9 10 11 12
 13 14 15 16

Unfortunately I'm stuck at being able to change the code so it will follow the pattern shown above.

Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire