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

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

Към профила на Красимир Атанасов

Резултати

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

Код

def interpret_chinese_sign(year):
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 not(year in range(1900, 1912)):
if year < 1900:
year += 12
else:
year -= 12
return year_signs[year]
def interpret_western_sign(day, month):
month_tuples = [
(20, "capricorn", "aquarius"),
(19, "aquarius", "pisces"),
(20, "pisces", "aries"),
(20, "aries", "taurus"),
(20, "taurus", "gemini"),
(20, "gemini", "cancer"),
(22, "cancer", "leo"),
(22, "leo", "virgo"),
(22, "virgo", "libra"),
(22, "libra", "scorpio"),
(21, "scorpio", "sagittarius"),
(21, "sagittarius", "capricorn")
]
border = 0
first_sign = 1
second_sign = 2
border_signs = month_tuples[month - 1]
if day <= border_signs[border]:
return border_signs[first_sign]
else:
return border_signs[second_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 версии и 6 коментара)

Красимир обнови решението на 11.03.2015 11:33 (преди над 9 години)

+def interpret_chinese_sign(year):
+ 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 not(year in range(1900, 1912)):
+ if year < 1900:
+ year += 12
+ else:
+ year -= 12
+
+ return year_signs[year]
+
+
+def interpret_western_sign(day, month):
+ months = [
+ ["capricorn"] * 20 + ["aquarius"] * 11, # January
+ ["aquarius"] * 19 + ["pisces"] * 8, # February
+ ["pisces"] * 20 + ["aries"] * 11, # March
+ ["aries"] * 20 + ["taurus"] * 10, # April
+ ["taurus"] * 20 + ["gemini"] * 11, # May
+ ["gemini"] * 20 + ["cancer"] * 9, # June
+ ["cancer"] * 22 + ["leo"] * 9, # July
+ ["leo"] * 22 + ["virgo"] * 9, # August
+ ["virgo"] * 22 + ["libra"] * 8, # September
+ ["libra"] * 22 + ["scorpio"] * 9, # October
+ ["scorpio"] * 21 + ["sagittarius"] * 9, # November
+ ["sagittarius"] * 21 + ["capricorn"] * 9 # December
+ ]
+
+ return months[month - 1][day - 1]
+
+
+def interpret_both_signs(day, month, year):
+ western_sign = interpret_western_sign(day, month)
+ chinese_sign = interpret_chinese_sign(year)
+
+ tup = (western_sign, chinese_sign)
+
+ return tup

Малко по-добре е от 12 if-а, има по-добро решение. В момента големината на списъка ти зависи от броя на дните в година, а не от броя на зодиите (12 елемента е далеч по-добре от 365, ако може да се постигне :))

Красимир обнови решението на 11.03.2015 15:25 (преди над 9 години)

def interpret_chinese_sign(year):
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 not(year in range(1900, 1912)):
if year < 1900:
year += 12
else:
year -= 12
return year_signs[year]
def interpret_western_sign(day, month):
- months = [
- ["capricorn"] * 20 + ["aquarius"] * 11, # January
- ["aquarius"] * 19 + ["pisces"] * 8, # February
- ["pisces"] * 20 + ["aries"] * 11, # March
- ["aries"] * 20 + ["taurus"] * 10, # April
- ["taurus"] * 20 + ["gemini"] * 11, # May
- ["gemini"] * 20 + ["cancer"] * 9, # June
- ["cancer"] * 22 + ["leo"] * 9, # July
- ["leo"] * 22 + ["virgo"] * 9, # August
- ["virgo"] * 22 + ["libra"] * 8, # September
- ["libra"] * 22 + ["scorpio"] * 9, # October
- ["scorpio"] * 21 + ["sagittarius"] * 9, # November
- ["sagittarius"] * 21 + ["capricorn"] * 9 # December
+ month_tuples = [
+ (20, "capricorn", "aquarius"),
+ (19, "aquarius", "pisces"),
+ (20, "pisces", "aries"),
+ (20, "aries", "taurus"),
+ (20, "taurus", "gemini"),
+ (20, "gemini", "cancer"),
+ (22, "cancer", "leo"),
+ (22, "leo", "virgo"),
+ (22, "virgo", "libra"),
+ (22, "libra", "scorpio"),
+ (21, "scorpio", "sagittarius"),
+ (21, "sagittarius", "capricorn")
]
- return months[month - 1][day - 1]
+ border = 0
+ first_sign = 1
+ second_sign = 2
+
+ border_signs = month_tuples[month - 1]
+
+ if day <= border_signs[border]:
+ return border_signs[first_sign]
+ else:
+ return border_signs[second_sign]
def interpret_both_signs(day, month, year):
western_sign = interpret_western_sign(day, month)
chinese_sign = interpret_chinese_sign(year)
tup = (western_sign, chinese_sign)
return tup

Красимир обнови решението на 11.03.2015 16:18 (преди над 9 години)

def interpret_chinese_sign(year):
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 not(year in range(1900, 1912)):
if year < 1900:
year += 12
else:
year -= 12
return year_signs[year]
def interpret_western_sign(day, month):
month_tuples = [
(20, "capricorn", "aquarius"),
(19, "aquarius", "pisces"),
(20, "pisces", "aries"),
(20, "aries", "taurus"),
(20, "taurus", "gemini"),
(20, "gemini", "cancer"),
(22, "cancer", "leo"),
(22, "leo", "virgo"),
(22, "virgo", "libra"),
(22, "libra", "scorpio"),
(21, "scorpio", "sagittarius"),
(21, "sagittarius", "capricorn")
]
border = 0
first_sign = 1
second_sign = 2
border_signs = month_tuples[month - 1]
if day <= border_signs[border]:
return border_signs[first_sign]
else:
return border_signs[second_sign]
def interpret_both_signs(day, month, year):
western_sign = interpret_western_sign(day, month)
chinese_sign = interpret_chinese_sign(year)
- tup = (western_sign, chinese_sign)
-
+ return western_sign, chinese_sign
- return tup