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

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

Към профила на Станислав Венков

Резултати

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

Код

WESTERN_SIGNS = {
'aries': {3: 21, 4: 20},
'taurus': {4: 21, 5: 20},
'gemini': {5: 21, 6: 20},
'cancer': {6: 21, 7: 22},
'leo': {7: 23, 8: 22},
'virgo': {8: 23, 9: 22},
'libra': {9: 23, 10: 22},
'scorpio': {10: 23, 11: 21},
'sagittarius': {11: 22, 12: 21},
'capricorn': {12: 22, 1: 20},
'aquarius': {1: 21, 2: 18},
'pisces': {2: 19, 3: 20}
}
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):
for sign, period in WESTERN_SIGNS.items():
if period.get(month, False):
previous_month = month - 1
next_month = month + 1
if next_month == 13:
next_month = 1
if previous_month == 0:
previous_month = 12
if (period.get(previous_month, False) and
day <= period.get(month, 0)):
return sign
elif (period.get(next_month, False) and
day >= period.get(month, 32)):
return sign
def interpret_chinese_sign(year):
sign = False
while not isinstance(sign, str):
sign = CHINESE_SIGNS.get(year, False)
if year < 1900:
year += 12
else:
year -= 12
return sign
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month), interpret_chinese_sign(year))

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

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

OK

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

Станислав обнови решението на 06.03.2015 22:22 (преди над 9 години)

+def interpret_western_sign(day, month):
+ signs = {
+ 'aries': {3: 21, 4: 20},
+ 'taurus': {4: 21, 5: 20},
+ 'gemini': {5: 21, 6: 20},
+ 'cancer': {6: 21, 7: 22},
+ 'leo': {7: 23, 8: 22},
+ 'virgo': {8: 23, 9: 22},
+ 'libra': {9: 23, 10: 22},
+ 'scorpio': {10: 23, 11: 21},
+ 'sagittarius': {11: 22, 12: 21},
+ 'capricorn': {12: 22, 1: 20},
+ 'aquarius': {1: 21, 2: 18},
+ 'pisces': {2: 19, 3: 20}
+ }
+
+ for sign, period in signs.items():
+ if period.get(month, False):
+ previous_month = month - 1
+ next_month = month + 1
+
+ if next_month == 13:
+ next_month = 1
+
+ if previous_month == 0:
+ previous_month = 12
+
+ if period.get(previous_month, False) and day <= period.get(month, 0):
+ return sign
+ elif period.get(next_month, False) and day >= period.get(month, 32):
+ return sign
+
+def interpret_chinese_sign(year):
+ 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'
+ }
+
+ while year > 1899:
+ sign = signs.get(year, False)
+ year -= 12
+
+ return sign
+
+def interpret_both_signs(day, month, year):
+ return (interpret_western_sign(day, month), interpret_chinese_sign(year))

Станислав обнови решението на 08.03.2015 21:45 (преди над 9 години)

def interpret_western_sign(day, month):
signs = {
'aries': {3: 21, 4: 20},
'taurus': {4: 21, 5: 20},
'gemini': {5: 21, 6: 20},
'cancer': {6: 21, 7: 22},
'leo': {7: 23, 8: 22},
'virgo': {8: 23, 9: 22},
'libra': {9: 23, 10: 22},
'scorpio': {10: 23, 11: 21},
'sagittarius': {11: 22, 12: 21},
'capricorn': {12: 22, 1: 20},
'aquarius': {1: 21, 2: 18},
'pisces': {2: 19, 3: 20}
}
for sign, period in signs.items():
if period.get(month, False):
previous_month = month - 1
next_month = month + 1
if next_month == 13:
next_month = 1
if previous_month == 0:
previous_month = 12
if period.get(previous_month, False) and day <= period.get(month, 0):
return sign
elif period.get(next_month, False) and day >= period.get(month, 32):
return sign
def interpret_chinese_sign(year):
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'
}
- while year > 1899:
+ sign = False
+
+ while not isinstance(sign, str):
sign = signs.get(year, False)
- year -= 12
+ if year < 1900:
+ year += 12
+ else:
+ year -= 12
return sign
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month), interpret_chinese_sign(year))

Добро решение. Имам една забележка - конвенцията за константи в Питон е името на променливата да е с ГЛАВНИ_БУКВИ и те да са в началото на файла. Много рядко има смисъл константата да е част от дефиницията на функцията ти.

Станислав обнови решението на 11.03.2015 11:29 (преди над 9 години)

+WESTERN_SIGNS = {
+ 'aries': {3: 21, 4: 20},
+ 'taurus': {4: 21, 5: 20},
+ 'gemini': {5: 21, 6: 20},
+ 'cancer': {6: 21, 7: 22},
+ 'leo': {7: 23, 8: 22},
+ 'virgo': {8: 23, 9: 22},
+ 'libra': {9: 23, 10: 22},
+ 'scorpio': {10: 23, 11: 21},
+ 'sagittarius': {11: 22, 12: 21},
+ 'capricorn': {12: 22, 1: 20},
+ 'aquarius': {1: 21, 2: 18},
+ 'pisces': {2: 19, 3: 20}
+}
+
+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):
- signs = {
- 'aries': {3: 21, 4: 20},
- 'taurus': {4: 21, 5: 20},
- 'gemini': {5: 21, 6: 20},
- 'cancer': {6: 21, 7: 22},
- 'leo': {7: 23, 8: 22},
- 'virgo': {8: 23, 9: 22},
- 'libra': {9: 23, 10: 22},
- 'scorpio': {10: 23, 11: 21},
- 'sagittarius': {11: 22, 12: 21},
- 'capricorn': {12: 22, 1: 20},
- 'aquarius': {1: 21, 2: 18},
- 'pisces': {2: 19, 3: 20}
- }
- for sign, period in signs.items():
+ for sign, period in WESTERN_SIGNS.items():
if period.get(month, False):
previous_month = month - 1
next_month = month + 1
if next_month == 13:
next_month = 1
if previous_month == 0:
previous_month = 12
if period.get(previous_month, False) and day <= period.get(month, 0):
return sign
elif period.get(next_month, False) and day >= period.get(month, 32):
return sign
+
def interpret_chinese_sign(year):
- 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'
- }
sign = False
while not isinstance(sign, str):
- sign = signs.get(year, False)
+ sign = CHINESE_SIGNS.get(year, False)
if year < 1900:
year += 12
else:
year -= 12
return sign
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month), interpret_chinese_sign(year))

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

WESTERN_SIGNS = {
'aries': {3: 21, 4: 20},
'taurus': {4: 21, 5: 20},
'gemini': {5: 21, 6: 20},
'cancer': {6: 21, 7: 22},
'leo': {7: 23, 8: 22},
'virgo': {8: 23, 9: 22},
'libra': {9: 23, 10: 22},
'scorpio': {10: 23, 11: 21},
'sagittarius': {11: 22, 12: 21},
'capricorn': {12: 22, 1: 20},
'aquarius': {1: 21, 2: 18},
'pisces': {2: 19, 3: 20}
}
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):
for sign, period in WESTERN_SIGNS.items():
if period.get(month, False):
previous_month = month - 1
next_month = month + 1
-
+
if next_month == 13:
next_month = 1
if previous_month == 0:
previous_month = 12
- if period.get(previous_month, False) and day <= period.get(month, 0):
+ if (period.get(previous_month, False) and
+ day <= period.get(month, 0)):
return sign
- elif period.get(next_month, False) and day >= period.get(month, 32):
+ elif (period.get(next_month, False) and
+ day >= period.get(month, 32)):
return sign
def interpret_chinese_sign(year):
sign = False
-
+
while not isinstance(sign, str):
sign = CHINESE_SIGNS.get(year, False)
if year < 1900:
year += 12
else:
year -= 12
return sign
+
def interpret_both_signs(day, month, year):
- return (interpret_western_sign(day, month), interpret_chinese_sign(year))
+ return (interpret_western_sign(day, month), interpret_chinese_sign(year))