python in hindi

Printing any word in right triangle shape using python

Hacker Rank Python

Printing any word in right triangle shape using python -In this blog, we will learn how to print any word in the shape of a right triangle. For this program, we will not use any of the modules. For creating this program we will use for loop.

Right triangle shape using python

Taking input of the word from the user.

For taking input from the user we will first make a variable in which we will right input() and the word entered by the user will be stored in that variable.

word = input("Enter the word\n") # This line will take input from the user and will store in in the 'word' variable


Here we can enter any word

Making for loop.

For making a for loop we will just write:-
for row in range(len(word)): here row is a new variable. Don’t forget to put colon(:) at the end of all for loops.
This for loop is for defining the number of rows in the right triangle.

After this we will make a other for loop inside the first for loop. This for loop will be for the number of columns in the triangle.

word = input("Enter the word\n")

for row in range(len(word)):
    for col in range(row+1):
        print(word[col],end=' ')


This is the final output

2 thoughts on “Printing any word in right triangle shape using python

Leave a Reply

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