Решение на Астрологични забави от Марио Даскалов

Обратно към всички решения

Към профила на Марио Даскалов

Резултати

  • 10 точки от тестове
  • 0 бонус точки
  • 10 точки общо
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)

Код

WESTERN_SIGNS_PERIODS = (
((3, 21), (4, 20), 'aries'),
((4, 21), (5, 20), 'taurus'),
((5, 21), (6, 20), 'gemini'),
((6, 21), (7, 22), 'cancer'),
((7, 23), (8, 22), 'leo'),
((8, 23), (9, 22), 'virgo'),
((9, 23), (10, 22), 'libra'),
((10, 23), (11, 21), 'scorpio'),
((11, 22), (12, 21), 'sagittarius'),
((12, 22), (1, 20), 'capricorn'),
((1, 21), (2, 18), 'aquarius'),
((2, 19), (3, 20), 'pisces'),
)
CHINESE_SIGNS = (
'rat', 'ox', 'tiger', 'rabbit', 'dragon', 'snake', 'horse',
'sheep', 'monkey', 'rooster', 'dog', 'pig'
)
def interpret_western_sign(day, month):
for start_date, end_date, sign in WESTERN_SIGNS_PERIODS:
if __date_between((month, day), start_date, end_date):
return sign
def __date_between(date, start_date, end_date):
if start_date[0] > end_date[0]:
if date[0] > end_date[0] and date[0] < start_date[0]:
return False
else:
if date[0] < start_date[0] or date[0] > end_date[0]:
return False
if date[0] == start_date[0]:
return date[1] >= start_date[1]
elif date[0] == end_date[0]:
return date[1] <= end_date[1]
else:
return True
def interpret_chinese_sign(year):
sign_index = (year - 1900) % len(CHINESE_SIGNS)
return CHINESE_SIGNS[sign_index]
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month), interpret_chinese_sign(year))

Лог от изпълнението

......
----------------------------------------------------------------------
Ran 6 tests in 0.006s

OK

История (1 версия и 0 коментара)

Марио обнови решението на 11.03.2015 12:35 (преди над 9 години)

+WESTERN_SIGNS_PERIODS = (
+ ((3, 21), (4, 20), 'aries'),
+ ((4, 21), (5, 20), 'taurus'),
+ ((5, 21), (6, 20), 'gemini'),
+ ((6, 21), (7, 22), 'cancer'),
+ ((7, 23), (8, 22), 'leo'),
+ ((8, 23), (9, 22), 'virgo'),
+ ((9, 23), (10, 22), 'libra'),
+ ((10, 23), (11, 21), 'scorpio'),
+ ((11, 22), (12, 21), 'sagittarius'),
+ ((12, 22), (1, 20), 'capricorn'),
+ ((1, 21), (2, 18), 'aquarius'),
+ ((2, 19), (3, 20), 'pisces'),
+ )
+CHINESE_SIGNS = (
+ 'rat', 'ox', 'tiger', 'rabbit', 'dragon', 'snake', 'horse',
+ 'sheep', 'monkey', 'rooster', 'dog', 'pig'
+ )
+
+
+def interpret_western_sign(day, month):
+ for start_date, end_date, sign in WESTERN_SIGNS_PERIODS:
+ if __date_between((month, day), start_date, end_date):
+ return sign
+
+
+def __date_between(date, start_date, end_date):
+ if start_date[0] > end_date[0]:
+ if date[0] > end_date[0] and date[0] < start_date[0]:
+ return False
+ else:
+ if date[0] < start_date[0] or date[0] > end_date[0]:
+ return False
+
+ if date[0] == start_date[0]:
+ return date[1] >= start_date[1]
+ elif date[0] == end_date[0]:
+ return date[1] <= end_date[1]
+ else:
+ return True
+
+
+def interpret_chinese_sign(year):
+ sign_index = (year - 1900) % len(CHINESE_SIGNS)
+ return CHINESE_SIGNS[sign_index]
+
+
+def interpret_both_signs(day, month, year):
+ return (interpret_western_sign(day, month), interpret_chinese_sign(year))