Skip to main content
added 37 characters in body
Source Link
Rahul K P
  • 16.1k
  • 4
  • 37
  • 54

Ruler printing can be down by pretty small function like this,

def print_ruler(n):
    print('|....'*(n-1)+'|')
    print(''.join(f'{i:<5}' for i in range(1,n+1)))

Execution:

In [1]: print_ruler(5)
|....|....|....|....|....|
0    1    2    3    4    5    

In [2]: print_ruler(10)
|....|....|....|....|....|....|....|....|....|....|
0    1    2    3    4    5    6    7    8    9    10    

In [3]: print_ruler(15)
|....|....|....|....|....|....|....|....|....|....|....|....|....|....|....|
0    1    2    3    4    5    6    7    8    9    10   11   12   13   14   15   

For double-digit numbers, It doesn't come to the center.

For ex: For 12, | align with number 1 or 2 it can't not make into the center of 12

Ruler printing can be down by pretty small function like this,

def print_ruler(n):
    print('|....'*(n-1)+'|')
    print(''.join(f'{i:<5}' for i in range(1,n+1)))

Execution:

In [1]: print_ruler(5)
|....|....|....|....|
1    2    3    4    5    

In [2]: print_ruler(10)
|....|....|....|....|....|....|....|....|....|
1    2    3    4    5    6    7    8    9    10    

In [3]: print_ruler(15)
|....|....|....|....|....|....|....|....|....|....|....|....|....|....|
1    2    3    4    5    6    7    8    9    10   11   12   13   14   15   

For double-digit numbers, It doesn't come to the center.

For ex: For 12, | align with number 1 or 2 it can't not make into the center of 12

Ruler printing can be down by pretty small function like this,

def print_ruler(n):
    print('|....'*(n)+'|')
    print(''.join(f'{i:<5}' for i in range(n+1)))

Execution:

In [1]: print_ruler(5)
|....|....|....|....|....|
0    1    2    3    4    5    

In [2]: print_ruler(10)
|....|....|....|....|....|....|....|....|....|....|
0    1    2    3    4    5    6    7    8    9    10   

In [3]: print_ruler(15)
|....|....|....|....|....|....|....|....|....|....|....|....|....|....|....|
0    1    2    3    4    5    6    7    8    9    10   11   12   13   14   15

For double-digit numbers, It doesn't come to the center.

For ex: For 12, | align with number 1 or 2 it can't not make into the center of 12

deleted 1 character in body
Source Link
Rahul K P
  • 16.1k
  • 4
  • 37
  • 54

Ruler printing can be down by pretty small function like this,

def print_ruler(n):
    print('|....'*(n-1)+'|')
    print(''.join(f'{i:<5}    ' for i in range(1,n+1)))

Execution:

In [1]: print_ruler(5)
|....|....|....|....|
1    2    3    4    5    

In [2]: print_ruler(10)
|....|....|....|....|....|....|....|....|....|
1    2    3    4    5    6    7    8    9    10    

In [3]: print_ruler(15)
|....|....|....|....|....|....|....|....|....|....|....|....|....|....|
1    2    3    4    5    6    7    8    9    10   11   12   13   14   15   

For double-digit numbers, It doesn't come to the center.

For ex: For 12, | align with number 1 or 2 it can't not make into the center of 12

Ruler printing can be down by pretty small function like this,

def print_ruler(n):
    print('|....'*(n-1)+'|')
    print(''.join(f'{i}    ' for i in range(1,n+1)))

Execution:

In [1]: print_ruler(5)
|....|....|....|....|
1    2    3    4    5    

In [2]: print_ruler(10)
|....|....|....|....|....|....|....|....|....|
1    2    3    4    5    6    7    8    9    10    

Ruler printing can be down by pretty small function like this,

def print_ruler(n):
    print('|....'*(n-1)+'|')
    print(''.join(f'{i:<5}' for i in range(1,n+1)))

Execution:

In [1]: print_ruler(5)
|....|....|....|....|
1    2    3    4    5    

In [2]: print_ruler(10)
|....|....|....|....|....|....|....|....|....|
1    2    3    4    5    6    7    8    9    10    

In [3]: print_ruler(15)
|....|....|....|....|....|....|....|....|....|....|....|....|....|....|
1    2    3    4    5    6    7    8    9    10   11   12   13   14   15   

For double-digit numbers, It doesn't come to the center.

For ex: For 12, | align with number 1 or 2 it can't not make into the center of 12

deleted 27 characters in body
Source Link
Rahul K P
  • 16.1k
  • 4
  • 37
  • 54

Ruler printing can be down by pretty small function like this,

In [1]: def print_ruler(n):
    ...:     print('|....'*(n-1)+'|')
    ...:     print(''.join(f'{i}    ' for i in range(1,n+1)))
    ...: 

Execution:

In [2][1]: print_ruler(5)
|....|....|....|....|
1    2    3    4    5    

In [3][2]: print_ruler(10)
|....|....|....|....|....|....|....|....|....|
1    2    3    4    5    6    7    8    9    10    

Ruler printing can be down by pretty small function like this,

In [1]: def print_ruler(n):
    ...:     print('|....'*(n-1)+'|')
    ...:     print(''.join(f'{i}    ' for i in range(1,n+1)))
    ...: 

In [2]: print_ruler(5)
|....|....|....|....|
1    2    3    4    5    

In [3]: print_ruler(10)
|....|....|....|....|....|....|....|....|....|
1    2    3    4    5    6    7    8    9    10    

Ruler printing can be down by pretty small function like this,

def print_ruler(n):
    print('|....'*(n-1)+'|')
    print(''.join(f'{i}    ' for i in range(1,n+1)))

Execution:

In [1]: print_ruler(5)
|....|....|....|....|
1    2    3    4    5    

In [2]: print_ruler(10)
|....|....|....|....|....|....|....|....|....|
1    2    3    4    5    6    7    8    9    10    
Source Link
Rahul K P
  • 16.1k
  • 4
  • 37
  • 54
Loading