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

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

Към профила на Христо Тодоров

Резултати

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

Код

from itertools import chain
def calculate_days(day, month):
day_of_months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
sum_of_the_days = 0
for x in range(0, month - 1):
sum_of_the_days += day_of_months[x]
sum_of_the_days += day
return sum_of_the_days
def interpret_western_sign(day, month):
if month == 2 and day == 29:
return "pisces"
sum_of_the_days = calculate_days(day, month)
zodiac_range = {"aquarius": range(21, 50), "pisces": range(50, 80),
"aries": range(80, 111), "taurus": range(111, 141),
"gemini": range(141, 172), "cancer": range(172, 204),
"leo": range(204, 235), "virgo": range(235, 266),
"libra": range(266, 296), "scorpio": range(296, 326),
"sagittarius": range(326, 356),
"capricorn": chain(range(356, 366), range(1, 21))}
for key in zodiac_range.keys():
if sum_of_the_days in zodiac_range[key]:
return key
def interpret_chinese_sign(year):
compute_diff = ((year - 1900) % 12)
chinese_sign = ["rat", "ox", "tiger", "rabbit", "dragon", "snake",
"horse", "sheep", "monkey", "rooster", "dog", "pig"]
return chinese_sign[compute_diff]
def interpret_both_signs(day, month, year):
get_western_sign = interpret_western_sign(day, month)
get_chinese_sign = interpret_chinese_sign(year)
return (get_western_sign, get_chinese_sign)

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

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

OK

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

Христо обнови решението на 09.03.2015 22:28 (преди над 9 години)

+from itertools import chain
+
+
+def calculate_days(day, month):
+ day_of_months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
+ sum_of_the_days = 0
+ for x in range(0, month - 1):
+ sum_of_the_days += day_of_months[x]
+ sum_of_the_days += day
+ return sum_of_the_days
+
+
+def interpret_western_sign(day, month):
+ if month == 2 and day == 29:
+ return "pisces"
+ sum_of_the_days = calculate_days(day, month)
+ zodiac_range = {"aquarius": range(21, 50), "pisces": range(50, 80),
+ "aries": range(80, 111), "taurus": range(111, 141),
+ "gemini": range(141, 172), "cancer": range(172, 204),
+ "leo": range(204, 235), "virgo": range(235, 266),
+ "libra": range(266, 296), "scorpio": range(296, 326),
+ "sagittarius": range(326, 356),
+ "capricorn": chain(range(356, 366), range(1, 21))}
+ for key in zodiac_range.keys():
+ if sum_of_the_days in zodiac_range[key]:
+ return key
+
+
+def interpret_chinese_sign(year):
+ compute_diff = ((year - 1900) % 12)
+ chinese_sign = ["rat", "ox", "tiger", "rabbit", "dragon", "snake",
+ "horse", "sheep", "monkey", "rooster", "dog", "pig"]
+ return chinese_sign[compute_diff]
+
+
+def interpret_both_signs(day, month, year):
+ get_western_sign = interpret_western_sign(day, month)
+ get_chinese_sign = interpret_chinese_sign(year)
+ return (get_western_sign, get_chinese_sign)