Answers
目前为止,python并不提供内置判断 季度 的方法。
实现的方法比较简单,有很多种,这里举例:
方法一:
for month in range(1, 13):
print (month-1)//3 + 1,
print
方法二:
import math
print math.ceil(month/3.)
方法三:
first, second, third, fourth=1,2,3,4# you can make strings if you wish :)
quarterMap = {}
quarterMap.update(dict(zip((1,2,3),(first,)*3)))
quarterMap.update(dict(zip((4,5,6),(second,)*3)))
quarterMap.update(dict(zip((7,8,9),(third,)*3)))
quarterMap.update(dict(zip((10,11,12),(fourth,)*3)))
print quarterMap[6]
ifoaf
answered 10 years, 3 months ago