Answer to Question #219416 in Python for chandu

Question #219416

Given an integer number

N as input. Write a program to print the hollow right-angled triangular pattern of N lines as shown below.Note: There is a space after each asterisk (*) character.

In the given example the hollow right angled triangle of side

4. Therefore, the output should be   

      *
    * *
  *   *
* * * *

5.Therefore, the output should be

        *
      * *
    *   *
  *     *
* * * * *
1
Expert's answer
2021-07-23T17:31:09-0400
N = int(input())

first_line = '*'.rjust(N * 2 - 1, ' ')
last_line = ('* ' * (N - 1) + '*').rjust(N, ' ')

triangle = first_line
for line in range(N - 2):
    triangle += '\n' + ('* ' + (' ' * line * 2) + '*').rjust(N * 2 - 1, ' ')
triangle += '\n' + last_line

print(triangle)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS