Triangle number pattern in python -


i'm doing patterns in python can't seem pattern change.

print("\npattern c")  c in range(1, 7 + 1):     cc in reversed(range(1, c)):         print(cc, end = '')     print('') 

this outputs:

pattern c  1 21 321 4321 54321 654321 

but want output:

     1     21    321   4321  54321 654321 

can please?

you have add spaces in way. 1 way subtract current counter fixed value , print many spaces.

for c in range(1, 7 + 1):     print(' '*(7-c), end='')     cc in reversed(range(1, c)):         print(cc, end = '')     print('') 

as aaron hall mentions in comments, there other ways produce output. example, single print() (and num representing 7+1 value above, , reversed() replaced different range() object):

for c in range(1, num):     print(' '*(num-1-c), *range(c-1, 0, -1), sep='') 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -