---
title: 'Python Challenge Day 8 - Quarter of the year'
disqus: hackmd
---
## Python Challenge Day 8 - Quarter of the year
### DESCRIPTION
Given a month as an integer from 1 to 12, return to which quarter of the year it belongs as an integer number.
For example: month 2 (February), is part of the first quarter; month 6 (June), is part of the second quarter; and month 11 (November), is part of the fourth quarter.
### Constraint
```gherkin=
1 <= month <= 12
```
程式邏輯
---
目的:給定一個從 1 到 12 的整數形式的月份,以整數形式返回它屬於一年中的哪個季度。
例如:二月是第一季度的一部分; 6 月是第二季度的一部分; 11 月是第四季度的一部分。
Solution
---
``` python
def quarter_of(month):
if 0<=(month/4) and (month/4)>=3.25:
return False
elif (month/4)>=2.5:
return 4
elif (month/4)>=1.75:
return 3
elif (month/4)>=1:
return 2
elif (month/4)>=0.25:
return 1
```
* 使用 def 關鍵字來定義函數(quarter_of)
* 第四季(10,11,12),第三季(7,8,9),第二季(4,5,6),第一季(1,2,3)
* 當月除以4大於等於該季最小月除以4
10/4=2.5,當月份為9,11/4>=2.5,則是第4季,以此類推
## 參考資源
:::info
* [Kata](https://www.codewars.com/kata/5ce9c1000bab0b001134f5af)
:::