String X-Pattern

The program must accept a string S as the input. The program must print the desired pattern as shown in the Example Input/Output section.

Boundary Condition(s)
3< Length of S<= 50

Input Format:
The first line contains S.

Output Format:
The lines containing the desired pattern as shown in the Example Input/Output section.

Example Input/Output 1:
Input

water
Output
w * * * a
* t * e *
* * r * *
* t * e *
w * * * a

Example Input/Output 2:
Input

OFFICE
Output
O * * * * F
* F * * I *
* * C E * *
* * C E * *
* F * * I *
O * * * * F

s=input().strip()
n=len(s);
ans = []
a=0
for i in range(len(s)):
    l=[]
    for j in range(len(s)):
        if i==j or j==n-i-1:
            l.append(s[a])
        else:
            l.append('*')
    ans.append(l)
    a+=1
for i in ans:
for j in i:
    print(j,end=" ")
print()

Leave a Reply

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

More posts. You may also be interested in.