Python-questions Given a positive integer ‘n’ less than or equal to 26, you are required to print the below pattern.

Python Question – 1

Alphabetic Patterns

Given a positive integer ‘n’ less than or equal to 26, you are required to print the below pattern.

Sample Input: 5

Sample Output :

——–e——–

——e-d-e——

—-e-d-c-d-e—-

–e-d-c-b-c-d-e–

e-d-c-b-a-b-c-d-e

–e-d-c-b-c-d-e–

—-e-d-c-d-e—-

——e-d-e——

——–e——–

Code:

import string n = int(input())
# Write your code below
x=string.ascii_lowercase list1=[] for i in range(n): a='-'.join(x[i:n]) list1.append((a[::-1]+a[1:])) width=len(list1[0])
# or width=(4*n)-3 ; this is basically the maximum width (row length) of the matrix
for i in range(n-1,0,-1): print(list1[i].center(width,'-')) for i in range(n): print(list1[i].center(width,'-')

Leave a Reply

Your email address will not be published. Required fields are marked *