Thursday, July 21, 2016

Loops - Hacker Rank Solution

Loops - Hacker Rank Solution

Task 
Read an integer . For all non-negative integers , print . See the sample for details.
Input Format
The first and only line contains the integer, .
Constraints
Output Format
Print  lines, one corresponding to each .
Sample Input
5
Sample Output
0
1
4
9
16

Loops - Hacker Rank Solution

Problem Tester's code :
for i in range(int(raw_input())):
    print i**2

21 comments:

  1. n=int(input())
    for i in range(n):
    print(i**2)

    ReplyDelete
    Replies
    1. so we dont have to mention negative integer
      Example i<0

      Delete
    2. def is_leap(year):
      if year % 400 == 0:
      return True
      elif year % 100 == 0:
      return False
      elif year % 400 == 0:
      return True
      elif year % 4 != 0:
      return False


      year = int(raw_input())
      print is_leap(year)

      Delete
    3. if year%4==0 and year%100!==0 or year%400==0:

      return True

      else:
      return False

      Delete
    4. n= int(input())
      For i in range(n):
      Print (i**2)

      Delete
  2. n=int(input())
    for i in range(n):
    if i < n:
    print(i**2)

    ReplyDelete
  3. for i in range(0,N):
    print (pow(i,2))

    ReplyDelete

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

    ReplyDelete
  5. n=int(input())
    for i in range(n):
    if i < n:
    print(i**2)

    ReplyDelete
  6. i = 0
    N = 5
    while i<N:
    sum = i*i
    i = i + 1
    print(sum)

    This is Shown wrong on HackerRank But On Pycharm i am getting the correct required output

    ReplyDelete
    Replies
    1. i= 0
      N = 5
      while i<N:
      sum = i*i
      i = i + 1
      print(sum)

      you tipe the code in this process it was true

      Delete
    2. It is showing error in hackerrank because user is asked there to input the value of n. And here, you have provided the value of n.

      Delete
  7. I am not able to understand can it been explained line by line

    ReplyDelete
  8. if __name__ == '__main__':
    n = int(input())

    count = -1
    while n > 0:
    count = count+1
    power = count*count
    n = n - 1
    print(power)
    The first and only line contains the integer, .

    Constraints

    ReplyDelete
  9. n = 5
    i = 0
    for i in range(n):
    print(i * i)
    e = i + 1

    This would work perfectly 👍👍👍

    ReplyDelete
    Replies
    1. n = int(input())
      i = 0
      for i in range(n):
      print(i * i)
      e = i + 1
      This is for all numbers.....

      Delete
    2. This is the most complete answer - passes all test cases...

      Delete
  10. if __name__ == '__main__':
    n = int(raw_input())
    for i in range(int(n)):
    print(i**2)

    this is right code

    ReplyDelete
  11. if __name__ == '__main__':
    n = int(input())
    i = 0

    for i in range(n):
    print(i * i)
    e = i + 1

    ReplyDelete
  12. if __name__ == '__main__':
    n = int(input())
    i = int
    for i in range(0,n):
    print(i**2)

    ReplyDelete

Powered by Blogger.