-2

This is the code:

def main():

    for i in range(1, 11):
        for j in range(1, 11):
            print(i*j, " ", end="")
        print()

main()

enter image description here

It should look like that with perfect lines and spaces between them. So how do i add spaces between them so that i can see it in the print screen

Barmar
  • 741,623
  • 53
  • 500
  • 612
Teemu
  • 49
  • 4

2 Answers2

1

You can use ljust()

This method returns the string left justified in a string of length width. Padding is done using the specified fillchar (default is a space). The original string is returned if width is less than len(s).

Source : tutorialspoint

for i in range(1, 11):
        for j in range(1, 11):
            print(str(i*j).ljust(2), " ", end="")
        print()
user3598726
  • 951
  • 2
  • 11
  • 27
1

This should work :)

def main():

    for i in range(1, 11):
        for j in range(1, 11):
            print('{:<3d}'.format(i*j), end="")
        print()

main()
chowsai
  • 565
  • 3
  • 15