Python 기본 사항쉬움

1년 중 특정 달의 일수 계산

'특정 월의 일 수 계산' 문제에 대한 자세한 가이드 및 Python 구현입니다.

문제 설명

쉬움

정수 month(1-12)과 정수 year를 사용하여 해당 월의 일수를 반환하는 days_in_month(month, year) 함수를 작성하세요.

기억하세요:

- 31일로 구성된 달: 1월(1), 3월(3), 5월(5), 7월(7), 8월(8), 10월(10), 12월(12)

- 30일이 있는 달 : 4월(4), 6월(6), 9월(9), 11월(11)

- 2월(2) : 평년 28일, 윤년 29일

- 윤년: 4로 나누어 떨어지지만 400으로 나누어지지 않는 한 100으로 나누어지지 않음

제약
  • 1 <= month <= 12
  • 1 <= year <= 9999

Example 1
Input
days_in_month(2, 2024)
Output
29
Explanation

2024 is divisible by 4 and not by 100, so it's a leap year. February has 29 days.

Example 2
Input
days_in_month(1, 2023)
Output
31
Explanation

January always has 31 days regardless of the year.

Example 3
Input
days_in_month(2, 1900)
Output
28
Explanation

1900 is divisible by 100 but not by 400, so it's NOT a leap year. February has 28 days.

Need a Hint?
세트나 힙과 같은 Numbers 관련 데이터 구조를 사용해 보세요.
Edge Cases to Watch
  • 빈 입력 구조
  • 단일 요소 입력
  • 큰 수치 범위

해결할 준비가 되셨나요?

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 리소스

관련 대화형 튜토리얼, 치트 시트, 코드 비교를 통해 지식을 확장하세요.