Write A Function In Python Hackerrank Solution
Published November 2, 2023 by Jarvis Silva
Looking for the Hackerrank write a function challenge solution in Python? You are at the right place. In this article, I will share the python function hackerrank solution.
Hackerrank is a popular online platform which has many programming challenges and competitions which allows developers to participate into them and improve their programming skill.
Question
Given a year, determine whether it is a leap year. If it is a leap year, return the Boolean True
, otherwise return False
. Note that the code stub provided reads from STDIN and passes arguments to the is_leap
function. It is only necessary to complete the is_leap
function.
You can find the full question of this problem here: Python Write A Function Hackerrank Question.
To solve this question we need to create a function to check leap year in python and in that function we need to return True if leap year and False if not a leap year so basically this we need to create a python program to check leap year.
Before moving to the solution you should definately try to do this on your own it is very easy but still if you can’t solve it don’t worry you can check the below solution and understand this program.
Python Write A Function Hackerrank Solution
def is_leap(year):
if year % 4:
return False
elif year % 100:
return True
elif year % 400:
return False
else:
return True
Above is the python solution for write a function Hackerrank challenge, you can submit the above code in hackerrank and it should show you congratulations you solved this challenge.
So this was for this article, I hope you found what you were looking and if you want more hackerrank solutions then visit here: Hackerrank python solutions.
Thank you for reading, Happy coding 😊