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

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

Към профила на Михаил Здравков

Резултати

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

Код

def is_date_in_period(date_day, date_month, period):
if date_month == period[1]:
return date_day >= period[0]
elif date_month == period[3]:
return date_day <= period[2]
return False
def interpret_western_sign(day, month):
calendar = {
(21, 3, 20, 4): 'aries',
(21, 4, 20, 5): 'taurus',
(21, 5, 20, 6): 'gemini',
(21, 6, 22, 7): 'cancer',
(23, 7, 22, 8): 'leo',
(23, 8, 22, 9): 'virgo',
(23, 9, 22, 10): 'libra',
(23, 10, 21, 11): 'scorpio',
(22, 11, 21, 12): 'sagittarius',
(22, 12, 20, 1): 'capricorn',
(21, 1, 18, 2): 'aquarius',
(19, 2, 20, 3): 'pisces',
}
for key in calendar:
if is_date_in_period(day, month, key):
return calendar[key]
def interpret_chinese_sign(year):
calendar = [
'rat',
'ox',
'tiger',
'rabbit',
'dragon',
'snake',
'horse',
'sheep',
'monkey',
'rooster',
'dog',
'pig']
return calendar[(year - 4) % 12]
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 коментара)

Михаил обнови решението на 07.03.2015 20:26 (преди около 9 години)

+def is_date_in_period(date_day, date_month, period):
+ if date_month == period[1]:
+ return date_day >= period[0]
+ elif date_month == period[3]:
+ return date_day <= period[2]
+ return False
+
+
+def interpret_western_sign(day, month):
+ calendar = {
+ (21, 3, 20, 4): 'aries',
+ (21, 4, 20, 5): 'taurus',
+ (21, 5, 20, 6): 'gemini',
+ (21, 6, 22, 7): 'cancer',
+ (23, 7, 22, 8): 'leo',
+ (23, 8, 22, 9): 'virgo',
+ (23, 9, 22, 10): 'libra',
+ (23, 10, 21, 11): 'scorpio',
+ (22, 11, 21, 12): 'sagittarius',
+ (22, 12, 20, 1): 'capricorn',
+ (21, 1, 18, 2): 'aquarius',
+ (19, 2, 20, 3): 'pisces',
+ }
+
+ for key in calendar:
+ if is_date_in_period(day, month, key):
+ return calendar[key]
+
+
+def interpret_chinese_sign(year):
+ calendar = [
+ 'rat',
+ 'ox',
+ 'tiger',
+ 'rabbit',
+ 'dragon',
+ 'snake',
+ 'horse',
+ 'sheep',
+ 'monkey',
+ 'rooster',
+ 'dog',
+ 'pig']
+ return calendar[(year - 4) % 12]
+
+
+def interpret_both_signs(day, month, year):
+ return (interpret_western_sign(day, month), interpret_chinese_sign(year))