Search code examples
pythonpalindromealphabet

I have to make a pyramid of letters in the middle of the screen i am able to print the pyramide but can not seem to get the alphabet and to go in


https://i.sstatic.net/5rpBR.png

https://i.sstatic.net/ZH04N.png

def full_pyramid(rows):

print('\nFull pyramid...\n')




for i in range(rows):



    print(' '*(rows-i-1) + '*'*(2*i+1))

string =" "

reversed_string = string[::-1]

result_string = " ".join(string)

for a in range(0 ,25):

result_string += chr(ord('a')+a)

Solution

  • This will do it

    Python 3.x :

    def pyramid(rows):
        s = "abcdefghijklmnopqrstuvwxyz"
        for i in range(rows, 0, -1):
            for j in range(i):
                print(' ', end='')
            for k in range(rows-i):
                print(s[k], end='')
            for m in range(rows-i, -1, -1):
                print(s[m], end='')
            print()
    
    pyramid(15)
    

    Python 2.x :

    def pyramid(rows):
        s = "abcdefghijklmnopqrstuvwxyz"
        for i in range(rows, 0, -1):
            for j in range(i):
                print(' '),
            for k in range(rows-i):
                print(s[k]),
            for m in range(rows-i, -1, -1):
                print(s[m]),
            print('')
    
    pyramid(15)