Alphabet Rangoli

  • + 10 comments

    I changed the code a bit so the width is simply the length of the center line. (Kudos to Boki for the original though - especially the appending line!)

    So e-d-c-b-a-b-c-d-e would make the width 17.

    Hopefully this helps some people with this question.

    import string
    alpha = string.ascii_lowercase
    
    n = int(input())
    L = []
    
    for i in range(n):
        s = "-".join(alpha[i:n])
        L.append(s[::-1]+s[1:])
    
    width = len(L[0])
    
    for i in range(n-1, 0, -1):
        print(L[i].center(width, "-"))
    
    for i in range(n):
        print(L[i].center(width, "-"))