Решение на Астрологични забави от Радослав Аспарухов

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

Към профила на Радослав Аспарухов

Резултати

  • 8 точки от тестове
  • 0 бонус точки
  • 8 точки общо
  • 5 успешни тест(а)
  • 1 неуспешни тест(а)

Код

from bisect import bisect
WESTERN_SIGNS = [(1, 20, "capricorn"), (2, 18, "aquarius"), (3, 20, "pisces"),
(4, 20, "aries"), (5, 21, "taurus"), (6, 21, "gemini"),
(7, 22, "cancer"), (8, 23, "leo"),
(9, 23, "virgo"), (10, 23, "libra"), (11, 22, "scorpio"),
(12, 22, "sagittarius"),
(12, 31, "capricorn")]
CHINESE_SIGNS = [(1900, "rat"), (1901, "ox"), (1902, "tiger"),
(1903, "rabbit"), (1904, "dragon"), (1905, "snake"),
(1906, "horse"), (1907, "sheep"), (1908, "monkey"),
(1909, "rooster"), (1910, "dog"), (1911, "pig")]
def interpret_western_sign(day, month):
if (month in [1, 3, 5, 7, 8, 10, 12] and 0 < day < 32 or
month in [4, 6, 9, 11] and 0 < day < 31 or
month == 2 and 0 < day < 29):
return WESTERN_SIGNS[bisect(WESTERN_SIGNS, (month, day))][2]
else:
raise Exception("Wrong date")
def interpret_chinese_sign(year):
return CHINESE_SIGNS[(year - CHINESE_SIGNS[0][0]) % 12][1]
def interpret_both_signs(day, month, year):
western_sign = interpret_western_sign(day, month)
chinese_sign = interpret_chinese_sign(year)
return western_sign, chinese_sign

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

..E...
======================================================================
ERROR: test_leap_year (test.TestSigns)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150312-24164-o5kz1a/test.py", line 32, in test_leap_year
    self.assertEqual(solution.interpret_western_sign(29, 2), 'pisces')
  File "/tmp/d20150312-24164-o5kz1a/solution.py", line 22, in interpret_western_sign
    raise Exception("Wrong date")
Exception: Wrong date

----------------------------------------------------------------------
Ran 6 tests in 0.007s

FAILED (errors=1)

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

Радослав обнови решението на 10.03.2015 22:37 (преди около 9 години)

+from bisect import bisect
+
+WESTERN_SIGNS = [(1, 20, "Capricorn"), (2, 18, "Aquarius"), (3, 20, "Pisces"),
+ (4, 20, "Aries"), (5, 21, "Taurus"), (6, 21, "Gemini"),
+ (7, 22, "Cancer"), (8, 23, "Leo"),
+ (9, 23, "Virgo"), (10, 23, "Libra"), (11, 22, "Scorpio"),
+ (12, 22, "Sagittarius"),
+ (12, 31, "Capricorn")]
+
+CHINESE_SIGNS = [(1900, "Rat"), (1901, "Ox"), (1902, "Tiger"),
+ (1903, "Rabbit"), (1904, "Dragon"), (1905, "Snake"),
+ (1906, "Horse"), (1907, "Sheep"), (1908, "Monkey"),
+ (1909, "Rooster"), (1910, "Dog"), (1911, "Pig")]
+
+
+def interpret_western_sign(day, month):
+ if (month in [1, 3, 5, 7, 8, 10, 12] and 0 < day < 32 or
+ month in [4, 6, 9, 11] and 0 < day < 31 or
+ month == 2 and 0 < day < 29):
+ return WESTERN_SIGNS[bisect(WESTERN_SIGNS, (month, day))][2]
+ else:
+ raise Exception("Wrong date")
+
+
+def interpret_chinese_sign(year):
+ return CHINESE_SIGNS[(year - CHINESE_SIGNS[0][0]) % 12][1]
+
+
+def interpret_both_signs(day, month, year):
+ western_sign = interpret_western_sign(day, month)
+ chinese_sign = interpret_chinese_sign(year)
+ return western_sign, chinese_sign

Радослав обнови решението на 10.03.2015 22:38 (преди около 9 години)

from bisect import bisect
WESTERN_SIGNS = [(1, 20, "Capricorn"), (2, 18, "Aquarius"), (3, 20, "Pisces"),
(4, 20, "Aries"), (5, 21, "Taurus"), (6, 21, "Gemini"),
(7, 22, "Cancer"), (8, 23, "Leo"),
(9, 23, "Virgo"), (10, 23, "Libra"), (11, 22, "Scorpio"),
(12, 22, "Sagittarius"),
(12, 31, "Capricorn")]
CHINESE_SIGNS = [(1900, "Rat"), (1901, "Ox"), (1902, "Tiger"),
(1903, "Rabbit"), (1904, "Dragon"), (1905, "Snake"),
(1906, "Horse"), (1907, "Sheep"), (1908, "Monkey"),
(1909, "Rooster"), (1910, "Dog"), (1911, "Pig")]
def interpret_western_sign(day, month):
if (month in [1, 3, 5, 7, 8, 10, 12] and 0 < day < 32 or
month in [4, 6, 9, 11] and 0 < day < 31 or
month == 2 and 0 < day < 29):
return WESTERN_SIGNS[bisect(WESTERN_SIGNS, (month, day))][2]
else:
raise Exception("Wrong date")
def interpret_chinese_sign(year):
return CHINESE_SIGNS[(year - CHINESE_SIGNS[0][0]) % 12][1]
def interpret_both_signs(day, month, year):
western_sign = interpret_western_sign(day, month)
chinese_sign = interpret_chinese_sign(year)
return western_sign, chinese_sign
+

Радослав обнови решението на 11.03.2015 08:45 (преди около 9 години)

from bisect import bisect
-WESTERN_SIGNS = [(1, 20, "Capricorn"), (2, 18, "Aquarius"), (3, 20, "Pisces"),
- (4, 20, "Aries"), (5, 21, "Taurus"), (6, 21, "Gemini"),
- (7, 22, "Cancer"), (8, 23, "Leo"),
- (9, 23, "Virgo"), (10, 23, "Libra"), (11, 22, "Scorpio"),
- (12, 22, "Sagittarius"),
- (12, 31, "Capricorn")]
+WESTERN_SIGNS = [(1, 20, "capricorn"), (2, 18, "aquarius"), (3, 20, "pisces"),
+ (4, 20, "aries"), (5, 21, "taurus"), (6, 21, "gemini"),
+ (7, 22, "cancer"), (8, 23, "leo"),
+ (9, 23, "virgo"), (10, 23, "libra"), (11, 22, "scorpio"),
+ (12, 22, "sagittarius"),
+ (12, 31, "capricorn")]
-CHINESE_SIGNS = [(1900, "Rat"), (1901, "Ox"), (1902, "Tiger"),
- (1903, "Rabbit"), (1904, "Dragon"), (1905, "Snake"),
- (1906, "Horse"), (1907, "Sheep"), (1908, "Monkey"),
- (1909, "Rooster"), (1910, "Dog"), (1911, "Pig")]
+CHINESE_SIGNS = [(1900, "rat"), (1901, "ox"), (1902, "tiger"),
+ (1903, "rabbit"), (1904, "dragon"), (1905, "snake"),
+ (1906, "horse"), (1907, "sheep"), (1908, "monkey"),
+ (1909, "rooster"), (1910, "dog"), (1911, "pig")]
def interpret_western_sign(day, month):
if (month in [1, 3, 5, 7, 8, 10, 12] and 0 < day < 32 or
month in [4, 6, 9, 11] and 0 < day < 31 or
month == 2 and 0 < day < 29):
return WESTERN_SIGNS[bisect(WESTERN_SIGNS, (month, day))][2]
else:
raise Exception("Wrong date")
def interpret_chinese_sign(year):
return CHINESE_SIGNS[(year - CHINESE_SIGNS[0][0]) % 12][1]
def interpret_both_signs(day, month, year):
western_sign = interpret_western_sign(day, month)
chinese_sign = interpret_chinese_sign(year)
return western_sign, chinese_sign
-