Home > Mobile >  Python program with letters pyramid
Python program with letters pyramid

Time:10-23

I need help with python. I have to do this and I don't know how can I add letters to * pyramid. Thank you first program second program

CodePudding user response:

This will help you:

length = 7          # length of the string
word = "Python"     # string to print

# first program
string = '.' * (length - 1)   word
for i in range(length - 1):
    print(string[i:i   length])

# second program
for i in range(1, length):
    _str = word[:i]   '.' * (length - i)
    print(_str[::-1]   _str)

The output is:

......P
.....Py
....Pyt
...Pyth
..Pytho
.Python
......PP......
.....yPPy.....
....tyPPyt....
...htyPPyth...
..ohtyPPytho..
.nohtyPPython.
  • Related