Python Basics簡単

Leap year or not

Detailed guide and Python implementation for the 'Leap year or not' problem.

問題提起

簡単

Write a function is_leap_year(year) that takes an integer year and returns True if the year is a leap year, or False otherwise. A year is a leap year if it is divisible by 4 but not by 100, except when it is also divisible by 400.

制約
  • 1 <= year <= 10^5

Example 1
Input
year = 2024
Output
True
Explanation

2024 is divisible by 4 and not by 100, so it is a leap year.

Example 2
Input
year = 1900
Output
False
Explanation

1900 is divisible by 100 but not by 400, so it is not a leap year.

Example 3
Input
year = 2000
Output
True
Explanation

2000 is divisible by 400, so it is a leap year.

Need a Hint?
Consider using Basics-specific data structures like sets or heaps.
Edge Cases to Watch
  • Empty input structures
  • Single element inputs
  • Large numerical bounds

解決する準備はできましたか?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

エディタで開く
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

推奨される Python リソース

関連するインタラクティブなチュートリアル、チートシート、コード比較で知識を深めてください。