Решение на Астрологични забави от Александър Танков

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

Към профила на Александър Танков

Резултати

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

Код

def interpret_western_sign(day, month):
sings = [(21, "aquarius", "capricorn"), (19, "pisces", "aquarius"),
(21, "aries", "pisces"), (21, "taurus", "aries"),
(21, "gemini", "taurus"), (21, "cancer", "gemini"),
(23, "leo", "cancer"), (23, "virgo", "leo"),
(23, "libra", "virgo"), (23, "scorpio", "libra"),
(22, "sagittarius", "scorpio"), (22, "capricorn", "sagittarius")]
if day >= sings[month - 1][0]:
return sings[month - 1][1]
else:
return sings[month - 1][2]
def interpret_chinese_sign(year):
chinese_zodiac = {
"rat": 0,
"ox": 1,
"tiger": 2,
"rabbit": 3,
"dragon": 4,
"snake": 5,
"horse": 6,
"sheep": 7,
"monkey": 8,
"rooster": 9,
"dog": 10,
"pig": 11
}
year_for_result = (year - 1900) % 12
for value in chinese_zodiac:
if chinese_zodiac[value] == year_for_result:
return value
return False
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month), interpret_chinese_sign(year))

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

......
----------------------------------------------------------------------
Ran 6 tests in 0.007s

OK

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

Александър обнови решението на 09.03.2015 22:36 (преди около 9 години)

+def interpret_western_sign(day, month):
+
+ sings = [(21, "aquarius", "capricorn"), (19, "pisces", "aquarius"),
+ (21, "aries", "pisces"), (21, "taurus", "aries"),
+ (21, "gemini", "taurus"), (21, "cancer", "gemini"),
+ (23, "leo", "cancer"), (23, "virgo", "leo"),
+ (23, "libra", "virgo"), (23, "scorpio", "libra"),
+ (22, "sagittarius", "scorpio"), (22, "capricorn", "sagittarius")]
+ idx = month - 1
+ return sings[idx][1] if day >= sings[idx][0] else sings[idx][2]
+
+
+def interpret_chinese_sign(year):
+ chinese_zodiac = {
+ "rat": 0,
+ "ox": 1,
+ "tiger": 2,
+ "rabbit": 3,
+ "dragon": 4,
+ "snake": 5,
+ "horse": 6,
+ "sheep": 7,
+ "monkey": 8,
+ "rooster": 9,
+ "dog": 10,
+ "pig": 11
+ }
+ year_for_result = (year - 1900) % 12
+ for value in chinese_zodiac:
+ if chinese_zodiac[value] == year_for_result:
+ return value
+ return False
+
+
+def interpret_both_signs(day, month, year):
+ return (interpret_western_sign(day, month), interpret_chinese_sign(year))
  • този речник с цели числа за value-та.. well you know it :)
  • явно те е хванало леко яд че ред 10 става над 79 символа ако не сложиш това idx, знам чувството повярвай ми. Все пак присвояваш нещо на още една променлива и т.н. Аз по-скоро бих си разбил if-а на няколко реда. Ако все пак решиш да ползваш oneline if с присвояване zodiac_sign = sings[month - 1] би изглеждало по-добре ми се струва.

Александър обнови решението на 10.03.2015 19:35 (преди около 9 години)

def interpret_western_sign(day, month):
sings = [(21, "aquarius", "capricorn"), (19, "pisces", "aquarius"),
(21, "aries", "pisces"), (21, "taurus", "aries"),
(21, "gemini", "taurus"), (21, "cancer", "gemini"),
(23, "leo", "cancer"), (23, "virgo", "leo"),
(23, "libra", "virgo"), (23, "scorpio", "libra"),
(22, "sagittarius", "scorpio"), (22, "capricorn", "sagittarius")]
- idx = month - 1
- return sings[idx][1] if day >= sings[idx][0] else sings[idx][2]
+ if day >= sings[month - 1][0]:
+ return sings[month - 1][1]
+ else:
+ return sings[month - 1][2]
def interpret_chinese_sign(year):
chinese_zodiac = {
"rat": 0,
"ox": 1,
"tiger": 2,
"rabbit": 3,
"dragon": 4,
"snake": 5,
"horse": 6,
"sheep": 7,
"monkey": 8,
"rooster": 9,
"dog": 10,
"pig": 11
}
year_for_result = (year - 1900) % 12
for value in chinese_zodiac:
if chinese_zodiac[value] == year_for_result:
return value
return False
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))