Решение на Астрологични забави от Васил Пачеджиев

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

Към профила на Васил Пачеджиев

Резултати

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

Код

def interpret_chinese_sign(year):
remainer = year - 2015
remainer = remainer % 12
signs = [
"sheep",
"monkey",
"rooster",
"dog",
"pig",
"rat",
"ox",
"tiger",
"rabbit",
"dragon",
"snake",
"horse"
]
return signs[remainer]
def interpret_western_sign(day, month):
incorrect_day = day <= 0 or day >= 32
incorrect_month = month <= 0 or month >= 13
if incorrect_day or incorrect_month:
return "Incorrect input"
sign_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")
]
for period in sign_periods:
left_border = period[0] == month and day >= period[1]
right_border = period[2] == month and day <= period[3]
if left_border or right_border:
return period[4]
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 версии и 0 коментара)

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

+def interpret_chinese_sign(year):
+ remainer = year - 2015
+ remainer = remainer % 12
+ signs = [
+ "sheep",
+ "monkey",
+ "rooster",
+ "dog",
+ "pig",
+ "rat",
+ "ox",
+ "tiger",
+ "rabbit",
+ "dragon",
+ "snake",
+ "horse"
+ ]
+
+ return signs[remainer]
+
+def interpret_western_sign(day, month):
+ incorrect_day = day <= 0 or day >= 32
+ incorrect_month = month <= 0 or month >= 13
+
+ if incorrect_day or incorrect_month:
+ return "Incorrect input"
+
+ sign_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")
+ ]
+
+ for period in sign_periods:
+ left_border = period[0] == month and day >= period[1]
+ right_border = period[2] == month and day <= period[3]
+ if left_border or right_border:
+ return period[4]
+
+
+
+
+def interpret_both_signs(day, month, year):
+ return (interpret_western_sign(day, month), interpret_chinese_sign(year))

Васил обнови решението на 11.03.2015 14:30 (преди над 9 години)

def interpret_chinese_sign(year):
remainer = year - 2015
remainer = remainer % 12
signs = [
"sheep",
"monkey",
"rooster",
"dog",
"pig",
"rat",
"ox",
"tiger",
"rabbit",
"dragon",
"snake",
"horse"
- ]
+ ]
return signs[remainer]
+
def interpret_western_sign(day, month):
incorrect_day = day <= 0 or day >= 32
incorrect_month = month <= 0 or month >= 13
if incorrect_day or incorrect_month:
return "Incorrect input"
sign_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")
- ]
+ (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")
+ ]
for period in sign_periods:
left_border = period[0] == month and day >= period[1]
right_border = period[2] == month and day <= period[3]
if left_border or right_border:
return period[4]
-
-
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month), interpret_chinese_sign(year))