0% found this document useful (0 votes)
112 views

Hackerrank Learning

This document provides two code examples for learning on HackerRank. The first example prints the squares of the numbers from 1 to a given integer n. The second example defines a function is_leap that returns True if the given year is a leap year, and False otherwise. It checks if a year is divisible by 4, 100, and 400 to determine if it is a leap year according to the Gregorian calendar system.

Uploaded by

AbhayRajSingh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
112 views

Hackerrank Learning

This document provides two code examples for learning on HackerRank. The first example prints the squares of the numbers from 1 to a given integer n. The second example defines a function is_leap that returns True if the given year is a leap year, and False otherwise. It checks if a year is divisible by 4, 100, and 400 to determine if it is a leap year according to the Gregorian calendar system.

Uploaded by

AbhayRajSingh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

HACKERRANK LEARNING

1. Read an integer . For all non-negative integers , print .


Code : if __name__ == '__main__':
n = int(input())
if(n>=1 and n<=20):
for i in range(n):
print(i**2) ( For exponential, use * twice )
2. Leap year function
Code :
def is_leap(year):
leap = False
if ( year//4 ==0 and year//400 ==0 and year//100 != 0):
# // : Gives remainder , != : Not equal, / : Division
leap= True
else:
leap= False

return leap

Code:
def is_leap(year): #% means mod in Python
leap = False
if ( year %4 ==0):
if(year%400 ==0):
leap= True
elif(year%100 !=0):
leap = True

else:
leap= False

return leap

You might also like