HackerRank Python Solution - Math Topic - Triangle Quest

  • 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 an 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:

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

    print((10**i)//9 * i)
Disclaimer: The problem statement is given by hackerrank.com but the solution is generated by the Geek4Tutorial admin. If there is any concern regarding this post or website, please contact us using the contact form. Thank you!

No comments:

Post a Comment

You might also like

Deploy your Django web app to Azure Web App using App Service - F1 free plan

In this post, we will look at how we can deploy our Django app using the Microsoft Azure app service - a free plan. You need an Azure accoun...