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

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

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

Резултати

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

Код

def interpret_chinese_sign(year):
chinese_signs = [
'rat',
'ox',
'tiger',
'rabbit',
'dragon',
'snake',
'horse',
'sheep',
'monkey',
'rooster',
'dog',
'pig'
]
base_year = 1900
signs_count = len(chinese_signs)
if year < base_year:
year += (year % signs_count) * signs_count
rest_years = year - base_year
sign_index = rest_years - signs_count * (int(rest_years / signs_count))
return chinese_signs[sign_index]
def interpret_western_sign(day, month):
western_signs = {
((21, 3), (20, 4)): 'aries',
((21, 4), (20, 5)): 'taurus',
((21, 5), (20, 6)): 'gemini',
((21, 6), (22, 7)): 'cancer',
((23, 7), (22, 8)): 'leo',
((23, 8), (22, 9)): 'virgo',
((23, 9), (22, 10)): 'libra',
((23, 10), (21, 11)): 'scorpio',
((22, 11), (21, 12)): 'sagittarius',
((22, 12), (20, 1)): 'capricorn',
((21, 1), (19, 2)): 'aquarius',
((19, 2), (20, 3)): 'pisces'
}
for sign in western_signs:
if ((sign[0][1] == month and day >= sign[0][0]) or
(sign[1][1] == month and day <= sign[1][0])):
return western_signs[sign]
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.006s

OK

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

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

+def interpret_chinese_sign(year):
+ chinese_signs = [
+ 'rat',
+ 'ox',
+ 'tiger',
+ 'rabbit',
+ 'dragon',
+ 'snake',
+ 'horse',
+ 'sheep',
+ 'monkey',
+ 'rooster',
+ 'dog',
+ 'pig'
+ ]
+ base_year = 1900
+
+ while year < base_year:
+ year += 12
+
+ while year >= base_year + 12:
+ year -= 12
+
+ sign_index = year - base_year
+
+ return chinese_signs[sign_index]
+
+
+def interpret_western_sign(day, month):
+ western_signs = {
+ ((21, 3), (20, 4)): 'aries',
+ ((21, 4), (20, 5)): 'taurus',
+ ((21, 5), (20, 6)): 'gemini',
+ ((21, 6), (22, 7)): 'cancer',
+ ((23, 7), (22, 8)): 'leo',
+ ((23, 8), (22, 9)): 'virgo',
+ ((23, 9), (22, 10)): 'libra',
+ ((23, 10), (21, 11)): 'scorpio',
+ ((22, 11), (21, 12)): 'sagittarius',
+ ((22, 12), (20, 1)): 'capricorn',
+ ((21, 1), (19, 2)): 'aquarius',
+ ((19, 2), (20, 3)): 'pisces'
+ }
+
+ for sign in western_signs:
+ if ((sign[0][1] == month and day >= sign[0][0]) or
+ (sign[1][1] == month and day <= sign[1][0])):
+ return western_signs[sign]
+
+
+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 15:43 (преди над 9 години)

+from math import ceil
+
+
def interpret_chinese_sign(year):
chinese_signs = [
'rat',
'ox',
'tiger',
'rabbit',
'dragon',
'snake',
'horse',
'sheep',
'monkey',
'rooster',
'dog',
'pig'
]
base_year = 1900
+ signs_count = len(chinese_signs)
- while year < base_year:
- year += 12
+ if year < base_year:
+ year += signs_count * int(ceil((base_year - year) / signs_count))
- while year >= base_year + 12:
- year -= 12
-
- sign_index = year - base_year
+ rest_years = year - base_year
+ sign_index = rest_years - signs_count * (int(rest_years / signs_count))
return chinese_signs[sign_index]
def interpret_western_sign(day, month):
western_signs = {
((21, 3), (20, 4)): 'aries',
((21, 4), (20, 5)): 'taurus',
((21, 5), (20, 6)): 'gemini',
((21, 6), (22, 7)): 'cancer',
((23, 7), (22, 8)): 'leo',
((23, 8), (22, 9)): 'virgo',
((23, 9), (22, 10)): 'libra',
((23, 10), (21, 11)): 'scorpio',
((22, 11), (21, 12)): 'sagittarius',
((22, 12), (20, 1)): 'capricorn',
((21, 1), (19, 2)): 'aquarius',
((19, 2), (20, 3)): 'pisces'
}
for sign in western_signs:
if ((sign[0][1] == month and day >= sign[0][0]) or
(sign[1][1] == month and day <= sign[1][0])):
return western_signs[sign]
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 16:08 (преди над 9 години)

-from math import ceil
-
-
def interpret_chinese_sign(year):
chinese_signs = [
'rat',
'ox',
'tiger',
'rabbit',
'dragon',
'snake',
'horse',
'sheep',
'monkey',
'rooster',
'dog',
'pig'
]
base_year = 1900
signs_count = len(chinese_signs)
if year < base_year:
- year += signs_count * int(ceil((base_year - year) / signs_count))
+ year += (year % signs_count) * signs_count
rest_years = year - base_year
sign_index = rest_years - signs_count * (int(rest_years / signs_count))
return chinese_signs[sign_index]
def interpret_western_sign(day, month):
western_signs = {
((21, 3), (20, 4)): 'aries',
((21, 4), (20, 5)): 'taurus',
((21, 5), (20, 6)): 'gemini',
((21, 6), (22, 7)): 'cancer',
((23, 7), (22, 8)): 'leo',
((23, 8), (22, 9)): 'virgo',
((23, 9), (22, 10)): 'libra',
((23, 10), (21, 11)): 'scorpio',
((22, 11), (21, 12)): 'sagittarius',
((22, 12), (20, 1)): 'capricorn',
((21, 1), (19, 2)): 'aquarius',
((19, 2), (20, 3)): 'pisces'
}
for sign in western_signs:
if ((sign[0][1] == month and day >= sign[0][0]) or
(sign[1][1] == month and day <= sign[1][0])):
return western_signs[sign]
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)