Home > Mobile >  How to make a string pyramid?
How to make a string pyramid?

Time:10-11

i want to make pyramid with string , i was confused for make a columns, please help:)

for example :

input :

row : 6
string: python

output

p
y p
t y p
h t y p
o h t y p
n o h t y p

and that's my code:

row = int(input('Input row:'))
string = input('Input string: ')
y = 0

for i in range(row):
    for j in range(i 1):
        list_string = string[y]
        print(list_string, end='')
        y  = 1
        if i == y - 1 :
            break
    print()

but the output is:

p
y
t
h
o
n

thank you:))

CodePudding user response:

row = int(input('Input row:'))
string = input('Input string: ')

for i in range(row):
    tmp=string[:i 1]
    print(tmp[::-1])
  • Related