Python #9 : Write a function
Welcome all to our new blog of our first series i.e., HackerRank Python Solutions, where we provide solutions to the problems given on HackerRank Website of Python.
So today's topic is writing a function.
The below code will be used or we could use to solve this type of problem. After spending nearly half an hour for just one error you are both convinced that you are dumb at start and genius at last. So here don't be dumb, just copy this code and paste it there you will be getting you next star very fast.
Code :
if year % 4 == 0: leap = True # Check if year is divisible by 100 if year % 100 == 0: leap = False # Check if year is divisible by 400 if year % 400 == 0: leap = True return leap
Explanation : This will check first for the leap year by just checking if the number is divisible by 4 or not then it will check if it is divisible by 100, coz leap year is not divisible by 10p, then it will check if it is divisible by 400, as leap year is divisible by 400.
Hence it will just change the value of Leap variable to trye and false, and this is only we had been asked in the problem. So if have any doubts please comment below. I am sure that we can solve your comment.
Till Then, #Coders😎
Recent Posts
See AllMy last blogg about gaming from your android, or my other blogs, that I published earlier were not a big hit, not like this website or...
Comments