Решение на Астрологични забави от Валентин Латунов

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

Към профила на Валентин Латунов

Резултати

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

Код

def interpret_western_sign(day, month):
interval_size = 50
signs = [
('aries', 3*interval_size + 21, 4*interval_size + 20),
('taurus', 4*interval_size + 21, 5*interval_size + 20),
('gemini', 5*interval_size + 21, 6*interval_size + 20),
('cancer', 6*interval_size + 21, 7*interval_size + 22),
('leo', 7*interval_size + 23, 8*interval_size + 22),
('virgo', 8*interval_size + 23, 9*interval_size + 22),
('libra', 9*interval_size + 23, 10*interval_size + 22),
('scorpio', 10*interval_size + 23, 11*interval_size + 21),
('sagittarius', 11*interval_size + 22, 12*interval_size + 21),
('capricorn', 12*interval_size + 22, 13*interval_size + 20),
('aquarius', 1*interval_size + 21, 2*interval_size + 18),
('pisces', 2*interval_size + 19, 3*interval_size + 20)
]
if month == 1 and day <= 20:
return 'capricorn'
else:
map_date = month*interval_size + day
for sign in signs:
if map_date >= sign[1] and map_date <= sign[2]:
return sign[0]
def interpret_chinese_sign(year):
signs = [
'rat', 'ox', 'tiger', 'rabbit',
'dragon', 'snake', 'horse', 'sheep',
'monkey', 'rooster', 'dog', 'pig'
]
return signs[(year - 1900) % 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

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

Валентин обнови решението на 10.03.2015 00:22 (преди над 9 години)

+def interpret_western_sign(day, month):
+ interval_size = 50
+ signs = [
+ ('aries', 3*interval_size + 21, 4*interval_size + 20),
+ ('taurus', 4*interval_size + 21, 5*interval_size + 20),
+ ('gemini', 5*interval_size + 21, 6*interval_size + 20),
+ ('cancer', 6*interval_size + 21, 7*interval_size + 22),
+ ('leo', 7*interval_size + 23, 8*interval_size + 22),
+ ('virgo', 8*interval_size + 23, 9*interval_size + 22),
+ ('libra', 9*interval_size + 23, 10*interval_size + 22),
+ ('scorpio', 10*interval_size + 23, 11*interval_size + 21),
+ ('sagittarius', 11*interval_size + 22, 12*interval_size + 21),
+ ('capricorn', 12*interval_size + 22, 13*interval_size + 20),
+ ('aquarius', 1*interval_size + 21, 2*interval_size + 18),
+ ('pisces', 2*interval_size + 19, 3*interval_size + 20)
+ ]
+ if month == 1 and day <= 20:
+ return 'capricorn'
+ else:
+ map_date = month*interval_size + day
+ for sign in signs:
+ if map_date >= sign[1] and map_date <= sign[2]:
+ return sign[0]
+
+
+def interpret_chinese_sign(year):
+ signs = [
+ 'rat', 'ox', 'tiger', 'rabbit',
+ 'dragon', 'snake', 'horse', 'sheep',
+ 'monkey', 'rooster', 'dog', 'pig'
+ ]
+ return signs[(year - 1900) % 12]
+
+
+def interpret_both_signs(day, month, year):
+ return (interpret_western_sign(day, month), interpret_chinese_sign(year))

Валентин обнови решението на 10.03.2015 22:19 (преди над 9 години)

def interpret_western_sign(day, month):
interval_size = 50
signs = [
- ('aries', 3*interval_size + 21, 4*interval_size + 20),
- ('taurus', 4*interval_size + 21, 5*interval_size + 20),
- ('gemini', 5*interval_size + 21, 6*interval_size + 20),
- ('cancer', 6*interval_size + 21, 7*interval_size + 22),
- ('leo', 7*interval_size + 23, 8*interval_size + 22),
- ('virgo', 8*interval_size + 23, 9*interval_size + 22),
- ('libra', 9*interval_size + 23, 10*interval_size + 22),
- ('scorpio', 10*interval_size + 23, 11*interval_size + 21),
+ ('aries', 3*interval_size + 21, 4*interval_size + 20),
+ ('taurus', 4*interval_size + 21, 5*interval_size + 20),
+ ('gemini', 5*interval_size + 21, 6*interval_size + 20),
+ ('cancer', 6*interval_size + 21, 7*interval_size + 22),
+ ('leo', 7*interval_size + 23, 8*interval_size + 22),
+ ('virgo', 8*interval_size + 23, 9*interval_size + 22),
+ ('libra', 9*interval_size + 23, 10*interval_size + 22),
+ ('scorpio', 10*interval_size + 23, 11*interval_size + 21),
('sagittarius', 11*interval_size + 22, 12*interval_size + 21),
- ('capricorn', 12*interval_size + 22, 13*interval_size + 20),
- ('aquarius', 1*interval_size + 21, 2*interval_size + 18),
- ('pisces', 2*interval_size + 19, 3*interval_size + 20)
+ ('capricorn', 12*interval_size + 22, 13*interval_size + 20),
+ ('aquarius', 1*interval_size + 21, 2*interval_size + 18),
+ ('pisces', 2*interval_size + 19, 3*interval_size + 20)
]
if month == 1 and day <= 20:
return 'capricorn'
else:
map_date = month*interval_size + day
for sign in signs:
if map_date >= sign[1] and map_date <= sign[2]:
return sign[0]
def interpret_chinese_sign(year):
signs = [
'rat', 'ox', 'tiger', 'rabbit',
'dragon', 'snake', 'horse', 'sheep',
'monkey', 'rooster', 'dog', 'pig'
]
return signs[(year - 1900) % 12]
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month), interpret_chinese_sign(year))