-4

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:))

daylooo
  • 11
  • 3
  • Also you don't need an additional counter, not to mention you can use negative ranges. E.g. `for j in range(i, -1, -1):` and use `string[j]` directly. – metatoaster Oct 10 '22 at 09:57

1 Answers1

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

for i in range(row):
    tmp=string[:i+1]
    print(tmp[::-1])
Ovecka
  • 34
  • 3