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

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

Към профила на Цветан Коев

Резултати

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

Код

CHINESE_SIGN = ['monkey', 'rooster', 'dog', 'pig', 'rat', 'ox',
'tiger', 'rabbit', 'dragon', 'snake', 'horse', 'sheep']
ZODIAC_SIGN = {
'aries': list(range(321, 332)) + list(range(401, 421)),
'taurus': list(range(421, 431)) + list(range(501, 521)),
'gemini': list(range(521, 532)) + list(range(601, 621)),
'cancer': list(range(621, 631)) + list(range(701, 723)),
'leo': list(range(723, 732)) + list(range(801, 823)),
'virgo': list(range(823, 832)) + list(range(901, 923)),
'libra': list(range(923, 931)) + list(range(1001, 1023)),
'scorpio': list(range(1023, 1032)) + list(range(1101, 1122)),
'sagittarius': list(range(1122, 1131)) + list(range(1201, 1222)),
'capricorn': list(range(1222, 1232)) + list(range(101, 121)),
'aquarius': list(range(121, 132)) + list(range(201, 219)),
'pisces': list(range(219, 230)) + list(range(301, 321))
}
def interpret_chinese_sign(year):
return CHINESE_SIGN[year % 12 if year >= 0 else 12 - abs(year) % 12]
def interpret_western_sign(day, month):
for key in ZODIAC_SIGN:
if (day + 100 * month) in ZODIAC_SIGN[key]:
return key
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month), interpret_chinese_sign(year))

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

......
----------------------------------------------------------------------
Ran 6 tests in 0.006s

OK

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

Цветан обнови решението на 09.03.2015 19:44 (преди над 9 години)

+chinese_sign = ['monkey', 'rooster', 'dog', 'pig', 'rat', 'ox',
+ 'tiger', 'rabbit', 'dragon', 'snake', 'horse', 'sheep']
+
+zodiac_sign = {
+ 'aries': list(range(321, 331)) + list(range(401, 420)),
+ 'taurus': list(range(421, 430)) + list(range(501, 520)),
+ 'gemini': list(range(521, 531)) + list(range(601, 620)),
+ 'cancer': list(range(621, 630)) + list(range(701, 722)),
+ 'leo': list(range(723, 731)) + list(range(801, 822)),
+ 'virgo': list(range(823, 831)) + list(range(901, 922)),
+ 'libra': list(range(932, 930)) + list(range(1001, 1022)),
+ 'scorpio': list(range(1023, 1031)) + list(range(1101, 1121)),
+ 'sagittarius': list(range(1122, 1130)) + list(range(1201, 1221)),
+ 'capricorn': list(range(1222, 1231)) + list(range(101, 120)),
+ 'aquarius': list(range(121, 131)) + list(range(201, 218)),
+ 'pisces': list(range(219, 229)) + list(range(301, 320))
+}
+
+
+def interpret_chinese_sign(year):
+ if year >= 0:
+ return chinese_sign[year % 12]
+ else:
+ return chinese_sign[12 - year % 12]
+
+
+def interpret_western_sign(day, month):
+ for key, value in zodiac_sign.items():
+ if (day + 100 * month) in value:
+ return key
+
+
+def interpret_both_signs(day, month, year):
+ return (interpret_western_sign(day, month), interpret_chinese_sign(year))

Цветан обнови решението на 09.03.2015 20:10 (преди над 9 години)

chinese_sign = ['monkey', 'rooster', 'dog', 'pig', 'rat', 'ox',
'tiger', 'rabbit', 'dragon', 'snake', 'horse', 'sheep']
zodiac_sign = {
'aries': list(range(321, 331)) + list(range(401, 420)),
'taurus': list(range(421, 430)) + list(range(501, 520)),
'gemini': list(range(521, 531)) + list(range(601, 620)),
'cancer': list(range(621, 630)) + list(range(701, 722)),
'leo': list(range(723, 731)) + list(range(801, 822)),
'virgo': list(range(823, 831)) + list(range(901, 922)),
'libra': list(range(932, 930)) + list(range(1001, 1022)),
'scorpio': list(range(1023, 1031)) + list(range(1101, 1121)),
'sagittarius': list(range(1122, 1130)) + list(range(1201, 1221)),
'capricorn': list(range(1222, 1231)) + list(range(101, 120)),
'aquarius': list(range(121, 131)) + list(range(201, 218)),
'pisces': list(range(219, 229)) + list(range(301, 320))
}
def interpret_chinese_sign(year):
if year >= 0:
return chinese_sign[year % 12]
else:
- return chinese_sign[12 - year % 12]
+ return chinese_sign[12 - abs(year) % 12]
def interpret_western_sign(day, month):
for key, value in zodiac_sign.items():
if (day + 100 * month) in value:
return key
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month), interpret_chinese_sign(year))

Цветан обнови решението на 09.03.2015 22:24 (преди над 9 години)

-chinese_sign = ['monkey', 'rooster', 'dog', 'pig', 'rat', 'ox',
+CHINESE_SIGN = ['monkey', 'rooster', 'dog', 'pig', 'rat', 'ox',
'tiger', 'rabbit', 'dragon', 'snake', 'horse', 'sheep']
-zodiac_sign = {
+ZODIAC_SIGN = {
'aries': list(range(321, 331)) + list(range(401, 420)),
'taurus': list(range(421, 430)) + list(range(501, 520)),
'gemini': list(range(521, 531)) + list(range(601, 620)),
'cancer': list(range(621, 630)) + list(range(701, 722)),
'leo': list(range(723, 731)) + list(range(801, 822)),
'virgo': list(range(823, 831)) + list(range(901, 922)),
'libra': list(range(932, 930)) + list(range(1001, 1022)),
'scorpio': list(range(1023, 1031)) + list(range(1101, 1121)),
'sagittarius': list(range(1122, 1130)) + list(range(1201, 1221)),
'capricorn': list(range(1222, 1231)) + list(range(101, 120)),
'aquarius': list(range(121, 131)) + list(range(201, 218)),
'pisces': list(range(219, 229)) + list(range(301, 320))
}
def interpret_chinese_sign(year):
- if year >= 0:
- return chinese_sign[year % 12]
- else:
- return chinese_sign[12 - abs(year) % 12]
+ return CHINESE_SIGN[year % 12 if year >= 0 else 12 - abs(year) % 12]
def interpret_western_sign(day, month):
- for key, value in zodiac_sign.items():
- if (day + 100 * month) in value:
+ for key in ZODIAC_SIGN:
+ if (day + 100 * month) in ZODIAC_SIGN[key]:
return key
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month), interpret_chinese_sign(year))

С риск другите от екипа да ми се скарат, ще ти кажа да се пробваш да пуснеш тестовете и на твои колеги от форума. Има една особеност (или не) на range(), която ми се струва е пропусната.

Цветан обнови решението на 10.03.2015 18:47 (преди над 9 години)

CHINESE_SIGN = ['monkey', 'rooster', 'dog', 'pig', 'rat', 'ox',
'tiger', 'rabbit', 'dragon', 'snake', 'horse', 'sheep']
ZODIAC_SIGN = {
- 'aries': list(range(321, 331)) + list(range(401, 420)),
- 'taurus': list(range(421, 430)) + list(range(501, 520)),
- 'gemini': list(range(521, 531)) + list(range(601, 620)),
- 'cancer': list(range(621, 630)) + list(range(701, 722)),
- 'leo': list(range(723, 731)) + list(range(801, 822)),
- 'virgo': list(range(823, 831)) + list(range(901, 922)),
- 'libra': list(range(932, 930)) + list(range(1001, 1022)),
- 'scorpio': list(range(1023, 1031)) + list(range(1101, 1121)),
- 'sagittarius': list(range(1122, 1130)) + list(range(1201, 1221)),
- 'capricorn': list(range(1222, 1231)) + list(range(101, 120)),
- 'aquarius': list(range(121, 131)) + list(range(201, 218)),
- 'pisces': list(range(219, 229)) + list(range(301, 320))
+ 'aries': list(range(321, 332)) + list(range(401, 421)),
+ 'taurus': list(range(421, 431)) + list(range(501, 521)),
+ 'gemini': list(range(521, 532)) + list(range(601, 621)),
+ 'cancer': list(range(621, 631)) + list(range(701, 723)),
+ 'leo': list(range(723, 732)) + list(range(801, 823)),
+ 'virgo': list(range(823, 832)) + list(range(901, 923)),
+ 'libra': list(range(923, 931)) + list(range(1001, 1023)),
+ 'scorpio': list(range(1023, 1032)) + list(range(1101, 1122)),
+ 'sagittarius': list(range(1122, 1131)) + list(range(1201, 1222)),
+ 'capricorn': list(range(1222, 1232)) + list(range(101, 121)),
+ 'aquarius': list(range(121, 132)) + list(range(201, 219)),
+ 'pisces': list(range(219, 230)) + list(range(301, 321))
}
def interpret_chinese_sign(year):
return CHINESE_SIGN[year % 12 if year >= 0 else 12 - abs(year) % 12]
def interpret_western_sign(day, month):
for key in ZODIAC_SIGN:
if (day + 100 * month) in ZODIAC_SIGN[key]:
return key
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month), interpret_chinese_sign(year))