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

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

Към профила на Елена Орешарова

Резултати

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

Код

CHINES_SIGNS = ['rat', 'ox', 'tiger', 'rabbit', 'dragon', 'snake',
'horse', 'sheep', 'monkey', 'rooster', 'dog', 'pig']
WESTERN_SIGNS = [[21, 'aquarius', 'capricorn'], # January
[19, 'pisces', 'aquarius'], # February
[21, 'aries', 'pisces'], # March
[21, 'taurus', 'aries'], # April
[21, 'gemini', 'taurus'], # May
[21, 'cancer', 'gemini'], # June
[23, 'leo', 'cancer'], # July
[23, 'virgo', 'leo'], # August
[23, 'libra', 'virgo'], # September
[23, 'scorpio', 'libra'], # October
[22, 'sagittarius', 'scorpio'], # November
[22, 'capricorn', 'sagittarius'], ] # December
def interpret_western_sign(day, month):
if day >= WESTERN_SIGNS[month - 1][0]:
sign = WESTERN_SIGNS[month - 1][1]
else:
sign = WESTERN_SIGNS[month - 1][2]
return sign
def interpret_chinese_sign(year):
return CHINES_SIGNS[(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

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

Елена обнови решението на 09.03.2015 20:16 (преди над 9 години)

+chinese_signs = {0: 'rat', 1: 'ox', 2: 'tiger',
+ 3: 'rabbit', 4: 'dragon', 5: 'snake',
+ 6: 'horse', 7: 'sheep', 8: 'monkey',
+ 9: 'rooster', 10: 'dog', 11: 'pig'}
+
+
+def interpret_western_sign(day, month):
+ if (month == 3):
+ return 'aries' if day >= 21 else 'pisces'
+ elif (month == 4):
+ return 'taurus' if day >= 21 else 'aries'
+ elif (month == 5):
+ return 'gemini' if day >= 21 else 'taurus'
+ elif (month == 6):
+ return 'cancer' if day >= 21 else 'gemini'
+ elif (month == 7):
+ return'leo' if day >= 23 else 'cancer'
+ elif (month == 8):
+ return 'virgo' if day >= 23 else 'leo'
+ elif (month == 9):
+ return 'libra' if day >= 23 else 'virgo'
+ elif (month == 10):
+ return 'scorpio' if day >= 23 else 'libra'
+ elif (month == 11):
+ return 'sagittarius' if day >= 22 else 'scorpio'
+ elif (month == 12):
+ return 'capricorn' if day >= 22 else 'sagittarius'
+ elif (month == 1):
+ return 'aquarius' if day >= 21 else 'capricorn'
+ elif (month == 2):
+ return 'pisces' if day >= 19 else 'aquarius'
+
+
+def interpret_chinese_sign(year):
+ return chinese_signs[(year - 4) % 12]
+
+
+def interpret_both_signs(day, month, year):
+ return (interpret_western_sign(day, month), interpret_chinese_sign(year))
  • константите са в SCREAM_SNAKE_CASE
  • пробвай да ползваш някоя структура от данни и в interpret_western_sign. Ако зодиите бяха повече, пак ли щеше да пишеш if-ове?
  • речник с ключове последователни цели числа, не ти ли напомня на нещо друго, което си е индексирано по default?
  • като изключим за константите, си отличник по PEP8 :)

Елена обнови решението на 11.03.2015 13:37 (преди над 9 години)

-chinese_signs = {0: 'rat', 1: 'ox', 2: 'tiger',
- 3: 'rabbit', 4: 'dragon', 5: 'snake',
- 6: 'horse', 7: 'sheep', 8: 'monkey',
- 9: 'rooster', 10: 'dog', 11: 'pig'}
+CHINES_SIGNS = ['rat', 'ox', 'tiger', 'rabbit', 'dragon', 'snake',
+ 'horse', 'sheep', 'monkey', 'rooster', 'dog', 'pig']
+WESTERN_SIGNS = [[21, 'aquarius', 'capricorn'], # January
+ [19, 'pisces', 'aquarius'], # February
+ [21, 'aries', 'pisces'], # March
+ [21, 'taurus', 'aries'], # April
+ [21, 'gemini', 'taurus'], # May
+ [21, 'cancer', 'gemini'], # June
+ [23, 'leo', 'cancer'], # July
+ [23, 'virgo', 'leo'], # August
+ [23, 'libra', 'virgo'], # September
+ [23, 'scorpio', 'libra'], # October
+ [22, 'sagittarius', 'scorpio'], # November
+ [22, 'capricorn', 'sagittarius'], # December
+ ]
+
def interpret_western_sign(day, month):
- if (month == 3):
- return 'aries' if day >= 21 else 'pisces'
- elif (month == 4):
- return 'taurus' if day >= 21 else 'aries'
- elif (month == 5):
- return 'gemini' if day >= 21 else 'taurus'
- elif (month == 6):
- return 'cancer' if day >= 21 else 'gemini'
- elif (month == 7):
- return'leo' if day >= 23 else 'cancer'
- elif (month == 8):
- return 'virgo' if day >= 23 else 'leo'
- elif (month == 9):
- return 'libra' if day >= 23 else 'virgo'
- elif (month == 10):
- return 'scorpio' if day >= 23 else 'libra'
- elif (month == 11):
- return 'sagittarius' if day >= 22 else 'scorpio'
- elif (month == 12):
- return 'capricorn' if day >= 22 else 'sagittarius'
- elif (month == 1):
- return 'aquarius' if day >= 21 else 'capricorn'
- elif (month == 2):
- return 'pisces' if day >= 19 else 'aquarius'
+ if day >= WESTERN_SIGNS[month - 1][0]:
+ sign = WESTERN_SIGNS[month - 1][1]
+ else:
+ sign = WESTERN_SIGNS[month - 1][2]
+ return sign
def interpret_chinese_sign(year):
- return chinese_signs[(year - 4) % 12]
+ return CHINES_SIGNS[(year - 4) % 12]
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month), interpret_chinese_sign(year))

Елена обнови решението на 11.03.2015 13:39 (преди над 9 години)

CHINES_SIGNS = ['rat', 'ox', 'tiger', 'rabbit', 'dragon', 'snake',
'horse', 'sheep', 'monkey', 'rooster', 'dog', 'pig']
WESTERN_SIGNS = [[21, 'aquarius', 'capricorn'], # January
[19, 'pisces', 'aquarius'], # February
[21, 'aries', 'pisces'], # March
[21, 'taurus', 'aries'], # April
[21, 'gemini', 'taurus'], # May
[21, 'cancer', 'gemini'], # June
[23, 'leo', 'cancer'], # July
[23, 'virgo', 'leo'], # August
[23, 'libra', 'virgo'], # September
[23, 'scorpio', 'libra'], # October
[22, 'sagittarius', 'scorpio'], # November
- [22, 'capricorn', 'sagittarius'], # December
- ]
+ [22, 'capricorn', 'sagittarius'], ] # December
def interpret_western_sign(day, month):
if day >= WESTERN_SIGNS[month - 1][0]:
sign = WESTERN_SIGNS[month - 1][1]
else:
sign = WESTERN_SIGNS[month - 1][2]
return sign
def interpret_chinese_sign(year):
return CHINES_SIGNS[(year - 4) % 12]
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month), interpret_chinese_sign(year))