Loops in Python | HackerRank Python Solution

Loops in Python - HackerRank Python Solution

Friends, How are you? Today I am going to solve the HackerRank Python Loop Problem with a very easy explanation. In this article, you will get one or more than one approaches to solving this problem. So let's start-

{tocify} $title={Table of Contents}

Time Delta - HackerRank Python Solution

HackerRank Python Loops Solution - Problem Statement

Task: 

The provided code stub reads an integer, n, from STDIN. For all non-negative integers, I <n, print i^2.

Example: 
n = 3
The list of non-negative integers that are less than n = 3 is [0, 1, 2]. Print the square of each number on a separate line.

0 1 4 {codeBox}

Input Format

The first and only line contains the integer, n.

Constraints

  • 1 <= n <= 20

Output Format

Print n lines, one corresponding to each i.

Sample Input 0

5 {codeBox}

Sample Output 0

0 1 4 9 16 {codeBox}

Loops in Python - Hacker Rank Solution

1st Approach: HackerRank Python Loops Solution

if __name__ == '__main__':
    n = int(input())
    for i in range(n):
        print(i*i);


Disclaimer: The above Problem ( Loops in Python ) is generated by Hackerrank but the Solution is Provided by MyEduWaves. This tutorial is only for Educational and Learning purposes. Authority if any queries regarding this post or website fill out the contact form.

I hope you have understood the solution to this HackerRank Problem. All these three solutions will pass all the test cases. Now visit Python Loops Hackerrank Problem and try to solve it again.

All the Best!

Post a Comment

Previous Post Next Post