- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Program to create one triangle stair by using stars in Python
Suppose we have a number n, we have to find a string of stairs with n steps. Here each line in the string is separated by a newline separator.
So, if the input is like n = 5, then the output will be
* ** *** **** *****
To solve this, we will follow these steps −
- s := blank string
- for i in range 0 to n-1, do
- s := s concatenate (n-i-1) number of blank space concatenate (i+1) number of stars
- if i < n-1, then
- s := add one new line after s
- return s
Let us see the following implementation to get better understanding −
Example
class Solution: def solve(self, n): s ="" for i in range(n): s+= " "*(n-i-1)+"*"*(i+1) if(i<n-1): s+="\n" return s ob = Solution() print(ob.solve(5))
Input
5
Output
* ** *** **** *****
- Related Articles
- How to create a triangle using Python for loop?
- Program to find largest perimeter triangle using Python
- C# Program to create Pascal’s Triangle
- Program to find island count by adding blocks into grid one by one in Python
- Python Program to Implement Stack using One Queue
- Python program to cyclically rotate an array by one
- Program to count substrings that differ by one character in Python
- Find the number of stair steps using C++
- Program to check one string can be converted to another by removing one element in Python
- Java program to print a given pattern. (stars)
- Python program to print number triangle
- How to Create a Triangle Using CSS clip-path
- How to create a canvas with Triangle using FabricJS?
- Count ways to reach the n’th stair
- Program to generate Pascal's triangle in Python

Advertisements