Triangle Quest in Python HackerRank Solution

Hello Programmers, In this post, you will know how to solve the Triangle Quest in Python HackerRank Solution. This problem is a part of the HackerRank Python Programming Series.

Triangle Quest in Python HackerRank Solution
Triangle Quest in Python HackerRank Solutions

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Hackerrank by yourself. If you find any difficulty after trying several times, then you can look for solutions.

Triangle Quest in Python HackerRank Solutions

problem

You are given a positive integer N. Print a numerical triangle of height N – 1 like the one below:

1
22
333
4444
55555
......

Can you do it using only arithmetic operations, a single for loop and print statement? Use no more than two lines. The first line (the for statement) is already written for you. You have to complete the print statement.
Note : Using anything related to strings will give a score of 0.

Input Format :

A single line containing integer,N.

Constraints :

  • 1 <= N <= 9

Output Format :

Print N -1 lines as explained above.

Sample Input :

5

Sample Output :

1
22
333
4444

Triangle Quest in Python HackerRank Solutions

for i in range(1, int(input())):  # More than 2 lines will result in 0 score. Do not leave a blank line also
    print(i * ((pow(10, i) - 1) // 9))

Disclaimer: The above Problem (Triangle Quest in Python) is generated by Hackerrank but the Solution is Provided by BrokenProgrammers. This tutorial is only for Educational and Learning purposes.

Next: itertools.product() in Python HackerRank Solution

Sharing Is Caring

Leave a Comment