Answer to Question #178416 in Python for phani

Question #178416
Right Angle Triangle
Given an integer N, write a program to print a right angle triangle pattern similar to the pattern shown below

    /|
   / |
  /  |
 /   |
/____|

Input

The input will be a single line containing a positive integer (N).
Output

The output should be N lines containing the triangle pattern.
Explanation

For example, if the given number is 5, the pattern should be printed in 5 lines, as shown below
    /|
   / |
  /  |
 /   |
/____|

Sample Input 1
5
Sample Output 1
    /|
   / |
  /  |
 /   |
/____|

Sample Input 2
4
Sample Output 2
   /|
  / |
 /  |
/___|
1
Expert's answer
2021-04-05T08:58:49-0400
n = int(input('Please enter a positive integer: '))
for i in range(n-1):
    print(' '*(n-1-i),'/',' '*i,'|',sep ='')
# last line print
print('/','_'*(n-1),'|',sep ='')

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

Shaik Amisha Begum
26.09.22, 09:43

Very helpful, thank you

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS