W pattern with *
Write a program to print
W pattern of N lines using an asterisk(*) character as shown below.
Note: There is a space after each asterisk * character.
Input
The first line is an integer
N.
Explanation
For
N = 5
The output should be
* * * * * * * * *
* * * * * * * *
* * * * * *
* * * *
* *
Sample Input 1
5
Sample Output 1
* * * * * * * * *
* * * * * * * *
* * * * * *
* * * *
* *
Sample Input 2
4
Sample Output 2
* * * * * * *
* * * * * *
* * * *
* *
def printW(N):
print("* " * (2 * N - 1))
for k in range(1, N):
print(" " * k, end="")
print("* " * (N - k), end="")
print(" " * (k - 1), end="")
print("* " * (N - k))
N = int(input())
printW(N)
Comments
Leave a comment