Saturday, June 27, 2020

Loops-HackerRank Solution

Loops-HackerRank Solution

Task
Read an integer N. For all non-negative integers i<N, print i^2 . See the sample for details.

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

Sample Output 0

0
1
4
9
16
Loops Solution-
def main(n):
    c=0
    while(c<n):
        print(c*c)
        c+=1
if __name__ == '__main__':
    n = int(input())
    main(n)
To read more about Loops follow this link-https://www.programiz.com/python-programming/while-loop

0 comments:

Post a Comment

Feel free to share your thoughts and suggestion...