Triangle Quest in Python - HackerRank Solution

Triangle Quest in Python - HackerRank Solution
Triangle Quest in Python - HackerRank Solution


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



Solution :


1
2
3
4
5
6
7
8
# Triangle Quest in Python - Hacker Rank Solution
# Python 3

for i in range(1,int(input())): 
#More than 2 lines will result in 0 score. Do not leave a blank line also
# Triangle Quest in Python - Hacker Rank Solution START
    print(int(i * 10**i / 9))
# Triangle Quest in Python - Hacker Rank Solution END





Disclaimer :-
the above hole problem statement is given by hackerrank.com but the solution is generated by the codeworld19 authority if any of the query regarding this post or website fill the following contact form thank you.

Next Post Previous Post
2 Comments
  • Anonymous
    Anonymous Saturday, September 24, 2022

    for i in range(1,int(input())):
    print(i * 10**i // 9)

  • Anonymous
    Anonymous Wednesday, October 05, 2022

    Wrong Answer
    more than two lines of code is not allowed

Add Comment
comment url