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

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

Към профила на Георги Павлов

Резултати

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

Код

CHINESE_SIGNS = ('rat', 'ox', 'tiger', 'rabbit', 'dragon', 'snake',
'horse', 'sheep', 'monkey', 'rooster', 'dog', 'pig')
WESTERN_SIGNS = ((3, 21, 'aries'), (4, 21, 'taurus'),
(5, 21, 'gemini'), (6, 21, 'cancer'),
(7, 23, 'leo'), (8, 23, 'virgo'),
(9, 23, 'libra'), (10, 23, 'scorpio'),
(11, 22, 'sagittarius'), (12, 22, 'capricorn'),
(1, 21, 'aquarius'), (2, 19, 'pisces'))
def interpret_chinese_sign(year):
return CHINESE_SIGNS[(year - 4) % 12]
def interpret_western_sign(day, month):
sign_edge = WESTERN_SIGNS[-1]
for next_edge in WESTERN_SIGNS:
if (sign_edge[0] is month and sign_edge[1] <= day
or next_edge[0] is month and next_edge[1] > day):
return sign_edge[2]
sign_edge = next_edge
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)

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

......
----------------------------------------------------------------------
Ran 6 tests in 0.008s

OK

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

Георги обнови решението на 11.03.2015 02:27 (преди над 9 години)

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

Подравняването на елементите на 'кортежите' по този начин приемливо ли е? pep8 не ми направи проблем и съм виждал ваши примери от лекциите с изброени елементи по същия начин, но пък ме наплашихте достатъчно с минало-годишните идентации > 4, че да питам. :)

Георги обнови решението на 11.03.2015 16:42 (преди над 9 години)

-chinese_signs = ('rat', 'ox', 'tiger', 'rabbit', 'dragon', 'snake',
- 'horse', 'sheep', 'monkey', 'rooster', 'dog', 'pig')
+CHINESE_SIGN = ('rat', 'ox', 'tiger', 'rabbit', 'dragon', 'snake',
+ 'horse', 'sheep', 'monkey', 'rooster', 'dog', 'pig')
-western_signs = ((3, 21, 'aries'), (4, 21, 'taurus'),
- (5, 21, 'gemini'), (6, 21, 'cancer'),
- (7, 23, 'leo'), (8, 23, 'virgo'),
- (9, 23, 'libra'), (10, 23, 'scorpio'),
- (11, 22, 'sagittarius'), (12, 22, 'capricorn'),
- (1, 21, 'aquarius'), (2, 19, 'pisces'))
+WESTERN_SIGN = ((3, 21, 'aries'), (4, 21, 'taurus'),
+ (5, 21, 'gemini'), (6, 21, 'cancer'),
+ (7, 23, 'leo'), (8, 23, 'virgo'),
+ (9, 23, 'libra'), (10, 23, 'scorpio'),
+ (11, 22, 'sagittarius'), (12, 22, 'capricorn'),
+ (1, 21, 'aquarius'), (2, 19, 'pisces'))
def interpret_chinese_sign(year):
- return chinese_signs[(year - 4) % 12]
+ return CHINESE_SIGN[(year - 4) % 12]
def interpret_western_sign(day, month):
- sign_edge = western_signs[-1]
- for next_edge in western_signs:
+ sign_edge = WESTERN_SIGN[-1]
+ for next_edge in WESTERN_SIGN:
if (sign_edge[0] is month and sign_edge[1] <= day
or next_edge[0] is month and next_edge[1] > day):
return sign_edge[2]
sign_edge = next_edge
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)
+ return (western_sign, chinese_sign)

Георги обнови решението на 11.03.2015 16:44 (преди над 9 години)

-CHINESE_SIGN = ('rat', 'ox', 'tiger', 'rabbit', 'dragon', 'snake',
- 'horse', 'sheep', 'monkey', 'rooster', 'dog', 'pig')
+CHINESE_SIGNS = ('rat', 'ox', 'tiger', 'rabbit', 'dragon', 'snake',
+ 'horse', 'sheep', 'monkey', 'rooster', 'dog', 'pig')
-WESTERN_SIGN = ((3, 21, 'aries'), (4, 21, 'taurus'),
- (5, 21, 'gemini'), (6, 21, 'cancer'),
- (7, 23, 'leo'), (8, 23, 'virgo'),
- (9, 23, 'libra'), (10, 23, 'scorpio'),
- (11, 22, 'sagittarius'), (12, 22, 'capricorn'),
- (1, 21, 'aquarius'), (2, 19, 'pisces'))
+WESTERN_SIGNS = ((3, 21, 'aries'), (4, 21, 'taurus'),
+ (5, 21, 'gemini'), (6, 21, 'cancer'),
+ (7, 23, 'leo'), (8, 23, 'virgo'),
+ (9, 23, 'libra'), (10, 23, 'scorpio'),
+ (11, 22, 'sagittarius'), (12, 22, 'capricorn'),
+ (1, 21, 'aquarius'), (2, 19, 'pisces'))
def interpret_chinese_sign(year):
- return CHINESE_SIGN[(year - 4) % 12]
+ return CHINESE_SIGNS[(year - 4) % 12]
def interpret_western_sign(day, month):
- sign_edge = WESTERN_SIGN[-1]
- for next_edge in WESTERN_SIGN:
+ sign_edge = WESTERN_SIGNS[-1]
+ for next_edge in WESTERN_SIGNS:
if (sign_edge[0] is month and sign_edge[1] <= day
or next_edge[0] is month and next_edge[1] > day):
return sign_edge[2]
sign_edge = next_edge
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)