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

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

Към профила на Янислав Василев

Резултати

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

Код

WESTERN_SIGNS = {(3, range(21, 32)): "aries",
(4, range(1, 21)): "aries",
(4, range(21, 31)): "taurus",
(5, range(1, 21)): "taurus",
(5, range(21, 32)): "gemini",
(6, range(1, 21)): "gemini",
(6, range(21, 31)): "cancer",
(7, range(1, 22)): "cancer",
(7, range(22, 32)): "leo",
(8, range(1, 23)): "leo",
(8, range(23, 32)): "virgo",
(9, range(1, 23)): "virgo",
(9, range(23, 31)): "libra",
(10, range(1, 23)): "libra",
(10, range(23, 32)): "scorpio",
(11, range(1, 22)): "scorpio",
(11, range(22, 31)): "sagittarius",
(12, range(1, 22)): "sagittarius",
(12, range(22, 32)): "capricorn",
(1, range(1, 20)): "capricorn",
(1, range(20, 32)): "aquarius",
(2, range(1, 19)): "aquarius",
(2, range(19, 30)): "pisces",
(3, range(1, 21)): "pisces"}
CHINESE_SIGNS = {4: "rat",
5: "ox",
6: "tiger",
7: "rabbit",
8: "dragon",
9: "snake",
10: "horse",
11: "sheep",
0: "monkey",
1: "rooster",
2: "dog",
3: "pig"}
def interpret_western_sign(day, month):
for key in WESTERN_SIGNS:
if month == key[0] and day in key[1]:
return WESTERN_SIGNS[key]
def interpret_chinese_sign(year):
for key in CHINESE_SIGNS:
if year % 12 in CHINESE_SIGNS.keys():
return CHINESE_SIGNS[year % 12]
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month), interpret_chinese_sign(year))

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

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

OK

История (6 версии и 7 коментара)

Янислав обнови решението на 06.03.2015 00:27 (преди над 9 години)

+def interpret_western_sign(day, month):
+ signs = {(3, range(21, 32)): "aries", (4, range(1, 21)): "aries",
+ (4, range(21, 31)): "taurus", (5, range(1, 21)): "taurus",
+ (5, range(21, 32)): "gemini", (6, range(1, 21)): "gemini",
+ (6, range(21, 31)): "cancer", (7, range(1, 22)): "cancer",
+ (7, range(22, 32)): "leo", (8, range(1, 23)): "leo",
+ (8, range(23, 32)): "vigro", (9, range(1, 23)): "vigro",
+ (9, range(23, 31)): "libra", (10, range(1, 23)): "libra",
+ (10, range(23, 32)): "scorpio", (11, range(1, 22)): "scorpio",
+ (11, range(22, 31)): "saggitarius", (12, range(1, 22)): "saggitarius",
+ (12, range(22, 32)): "capricorn", (1, range(1, 20)): "capricorn",
+ (1, range(20, 32)): "aquarius", (2, range(1, 19)): "aquarius",
+ (2, range(19, 30)): "pisces", (3, range(1, 21)): "pisces"}
+ for key in signs:
+ if month == key[0] and day in key[1]:
+ return signs[key]
+
+
+def interpret_chinese_sign(year):
+ signs = {4: "rat", 5: "ox", 6: "tiger", 7: "rabbit", 8: "dragon", 9: "snake",
+ 10: "horse", 11: "sheep", 0: "monkey", 1: "rooster", 2: "dog", 3: "pig"}
+ for key in signs:
+ if year % 12 in signs.keys():
+ return signs[year % 12]
+
+
+def interpret_both_signs(day, month, year):
+ return (interpret_western_sign(day, month), interpret_chinese_sign(year))

Янислав обнови решението на 06.03.2015 15:39 (преди над 9 години)

def interpret_western_sign(day, month):
- signs = {(3, range(21, 32)): "aries", (4, range(1, 21)): "aries",
- (4, range(21, 31)): "taurus", (5, range(1, 21)): "taurus",
- (5, range(21, 32)): "gemini", (6, range(1, 21)): "gemini",
- (6, range(21, 31)): "cancer", (7, range(1, 22)): "cancer",
- (7, range(22, 32)): "leo", (8, range(1, 23)): "leo",
- (8, range(23, 32)): "vigro", (9, range(1, 23)): "vigro",
- (9, range(23, 31)): "libra", (10, range(1, 23)): "libra",
- (10, range(23, 32)): "scorpio", (11, range(1, 22)): "scorpio",
- (11, range(22, 31)): "saggitarius", (12, range(1, 22)): "saggitarius",
- (12, range(22, 32)): "capricorn", (1, range(1, 20)): "capricorn",
- (1, range(20, 32)): "aquarius", (2, range(1, 19)): "aquarius",
- (2, range(19, 30)): "pisces", (3, range(1, 21)): "pisces"}
+ signs = {(3, range(21, 32)): "aries",
+ (4, range(1, 21)): "aries",
+ (4, range(21, 31)): "taurus",
+ (5, range(1, 21)): "taurus",
+ (5, range(21, 32)): "gemini",
+ (6, range(1, 21)): "gemini",
+ (6, range(21, 31)): "cancer",
+ (7, range(1, 22)): "cancer",
+ (7, range(22, 32)): "leo",
+ (8, range(1, 23)): "leo",
+ (8, range(23, 32)): "vigro",
+ (9, range(1, 23)): "vigro",
+ (9, range(23, 31)): "libra",
+ (10, range(1, 23)): "libra",
+ (10, range(23, 32)): "scorpio",
+ (11, range(1, 22)): "scorpio",
+ (11, range(22, 31)): "saggitarius",
+ (12, range(1, 22)): "saggitarius",
+ (12, range(22, 32)): "capricorn",
+ (1, range(1, 20)): "capricorn",
+ (1, range(20, 32)): "aquarius",
+ (2, range(1, 19)): "aquarius",
+ (2, range(19, 30)): "pisces",
+ (3, range(1, 21)): "pisces"}
for key in signs:
if month == key[0] and day in key[1]:
return signs[key]
def interpret_chinese_sign(year):
- signs = {4: "rat", 5: "ox", 6: "tiger", 7: "rabbit", 8: "dragon", 9: "snake",
- 10: "horse", 11: "sheep", 0: "monkey", 1: "rooster", 2: "dog", 3: "pig"}
+ signs = {4: "rat",
+ 5: "ox",
+ 6: "tiger",
+ 7: "rabbit",
+ 8: "dragon",
+ 9: "snake",
+ 10: "horse",
+ 11: "sheep",
+ 0: "monkey",
+ 1: "rooster",
+ 2: "dog",
+ 3: "pig"}
for key in signs:
if year % 12 in signs.keys():
return signs[year % 12]
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month), interpret_chinese_sign(year))

Сега ги направих , да са съгласно PEP8 (до колкото видях такъв е начина на записване на речници) , благодаря за поправката , не бях обръщал внимание :) Колкото до тестовете , пуснах ги нямаше проблем пък и аз си имах свои ;)

Янислав обнови решението на 06.03.2015 16:50 (преди над 9 години)

def interpret_western_sign(day, month):
signs = {(3, range(21, 32)): "aries",
(4, range(1, 21)): "aries",
(4, range(21, 31)): "taurus",
(5, range(1, 21)): "taurus",
(5, range(21, 32)): "gemini",
(6, range(1, 21)): "gemini",
(6, range(21, 31)): "cancer",
(7, range(1, 22)): "cancer",
(7, range(22, 32)): "leo",
(8, range(1, 23)): "leo",
- (8, range(23, 32)): "vigro",
- (9, range(1, 23)): "vigro",
+ (8, range(23, 32)): "virgo",
+ (9, range(1, 23)): "virgo",
(9, range(23, 31)): "libra",
(10, range(1, 23)): "libra",
(10, range(23, 32)): "scorpio",
(11, range(1, 22)): "scorpio",
(11, range(22, 31)): "saggitarius",
(12, range(1, 22)): "saggitarius",
(12, range(22, 32)): "capricorn",
(1, range(1, 20)): "capricorn",
(1, range(20, 32)): "aquarius",
(2, range(1, 19)): "aquarius",
(2, range(19, 30)): "pisces",
(3, range(1, 21)): "pisces"}
for key in signs:
if month == key[0] and day in key[1]:
return signs[key]
def interpret_chinese_sign(year):
signs = {4: "rat",
5: "ox",
6: "tiger",
7: "rabbit",
8: "dragon",
9: "snake",
10: "horse",
11: "sheep",
0: "monkey",
1: "rooster",
2: "dog",
3: "pig"}
for key in signs:
if year % 12 in signs.keys():
return signs[year % 12]
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month), interpret_chinese_sign(year))

Супер.

Като препоръка: изнеси двата речника извън функциите, за да са константи. Което в python е просто конвенция, която изисква имената им да са в SCREAMING_SNAKE_CASE (в твоя случай WESTERN_SIGNS и CHINESE_SIGNS).

Янислав обнови решението на 06.03.2015 21:52 (преди над 9 години)

+WESTERN_SIGNS = {(3, range(21, 32)): "aries",
+ (4, range(1, 21)): "aries",
+ (4, range(21, 31)): "taurus",
+ (5, range(1, 21)): "taurus",
+ (5, range(21, 32)): "gemini",
+ (6, range(1, 21)): "gemini",
+ (6, range(21, 31)): "cancer",
+ (7, range(1, 22)): "cancer",
+ (7, range(22, 32)): "leo",
+ (8, range(1, 23)): "leo",
+ (8, range(23, 32)): "virgo",
+ (9, range(1, 23)): "virgo",
+ (9, range(23, 31)): "libra",
+ (10, range(1, 23)): "libra",
+ (10, range(23, 32)): "scorpio",
+ (11, range(1, 22)): "scorpio",
+ (11, range(22, 31)): "saggitarius",
+ (12, range(1, 22)): "saggitarius",
+ (12, range(22, 32)): "capricorn",
+ (1, range(1, 20)): "capricorn",
+ (1, range(20, 32)): "aquarius",
+ (2, range(1, 19)): "aquarius",
+ (2, range(19, 30)): "pisces",
+ (3, range(1, 21)): "pisces"}
+CHINESE_SIGNS = {4: "rat",
+ 5: "ox",
+ 6: "tiger",
+ 7: "rabbit",
+ 8: "dragon",
+ 9: "snake",
+ 10: "horse",
+ 11: "sheep",
+ 0: "monkey",
+ 1: "rooster",
+ 2: "dog",
+ 3: "pig"}
+
+
def interpret_western_sign(day, month):
- signs = {(3, range(21, 32)): "aries",
- (4, range(1, 21)): "aries",
- (4, range(21, 31)): "taurus",
- (5, range(1, 21)): "taurus",
- (5, range(21, 32)): "gemini",
- (6, range(1, 21)): "gemini",
- (6, range(21, 31)): "cancer",
- (7, range(1, 22)): "cancer",
- (7, range(22, 32)): "leo",
- (8, range(1, 23)): "leo",
- (8, range(23, 32)): "virgo",
- (9, range(1, 23)): "virgo",
- (9, range(23, 31)): "libra",
- (10, range(1, 23)): "libra",
- (10, range(23, 32)): "scorpio",
- (11, range(1, 22)): "scorpio",
- (11, range(22, 31)): "saggitarius",
- (12, range(1, 22)): "saggitarius",
- (12, range(22, 32)): "capricorn",
- (1, range(1, 20)): "capricorn",
- (1, range(20, 32)): "aquarius",
- (2, range(1, 19)): "aquarius",
- (2, range(19, 30)): "pisces",
- (3, range(1, 21)): "pisces"}
- for key in signs:
+ for key in WESTERN_SIGNS:
if month == key[0] and day in key[1]:
- return signs[key]
+ return WESTERN_SIGNS[key]
def interpret_chinese_sign(year):
- signs = {4: "rat",
- 5: "ox",
- 6: "tiger",
- 7: "rabbit",
- 8: "dragon",
- 9: "snake",
- 10: "horse",
- 11: "sheep",
- 0: "monkey",
- 1: "rooster",
- 2: "dog",
- 3: "pig"}
- for key in signs:
- if year % 12 in signs.keys():
- return signs[year % 12]
+ for key in CHINESE_SIGNS:
+ if year % 12 in CHINESE_SIGNS.keys():
+ return CHINESE_SIGNS[year % 12]
+
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))

Янислав обнови решението на 07.03.2015 01:44 (преди над 9 години)

WESTERN_SIGNS = {(3, range(21, 32)): "aries",
(4, range(1, 21)): "aries",
(4, range(21, 31)): "taurus",
(5, range(1, 21)): "taurus",
(5, range(21, 32)): "gemini",
(6, range(1, 21)): "gemini",
(6, range(21, 31)): "cancer",
(7, range(1, 22)): "cancer",
(7, range(22, 32)): "leo",
(8, range(1, 23)): "leo",
(8, range(23, 32)): "virgo",
(9, range(1, 23)): "virgo",
(9, range(23, 31)): "libra",
(10, range(1, 23)): "libra",
(10, range(23, 32)): "scorpio",
(11, range(1, 22)): "scorpio",
(11, range(22, 31)): "saggitarius",
(12, range(1, 22)): "saggitarius",
(12, range(22, 32)): "capricorn",
(1, range(1, 20)): "capricorn",
(1, range(20, 32)): "aquarius",
(2, range(1, 19)): "aquarius",
(2, range(19, 30)): "pisces",
(3, range(1, 21)): "pisces"}
CHINESE_SIGNS = {4: "rat",
5: "ox",
6: "tiger",
7: "rabbit",
8: "dragon",
9: "snake",
10: "horse",
11: "sheep",
0: "monkey",
1: "rooster",
2: "dog",
3: "pig"}
def interpret_western_sign(day, month):
for key in WESTERN_SIGNS:
if month == key[0] and day in key[1]:
return WESTERN_SIGNS[key]
def interpret_chinese_sign(year):
-
for key in CHINESE_SIGNS:
if year % 12 in CHINESE_SIGNS.keys():
return CHINESE_SIGNS[year % 12]
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month), interpret_chinese_sign(year))

Янислав обнови решението на 07.03.2015 14:38 (преди над 9 години)

WESTERN_SIGNS = {(3, range(21, 32)): "aries",
(4, range(1, 21)): "aries",
(4, range(21, 31)): "taurus",
(5, range(1, 21)): "taurus",
(5, range(21, 32)): "gemini",
(6, range(1, 21)): "gemini",
(6, range(21, 31)): "cancer",
(7, range(1, 22)): "cancer",
(7, range(22, 32)): "leo",
(8, range(1, 23)): "leo",
(8, range(23, 32)): "virgo",
(9, range(1, 23)): "virgo",
(9, range(23, 31)): "libra",
(10, range(1, 23)): "libra",
(10, range(23, 32)): "scorpio",
(11, range(1, 22)): "scorpio",
- (11, range(22, 31)): "saggitarius",
- (12, range(1, 22)): "saggitarius",
+ (11, range(22, 31)): "sagittarius",
+ (12, range(1, 22)): "sagittarius",
(12, range(22, 32)): "capricorn",
(1, range(1, 20)): "capricorn",
(1, range(20, 32)): "aquarius",
(2, range(1, 19)): "aquarius",
(2, range(19, 30)): "pisces",
(3, range(1, 21)): "pisces"}
CHINESE_SIGNS = {4: "rat",
5: "ox",
6: "tiger",
7: "rabbit",
8: "dragon",
9: "snake",
10: "horse",
11: "sheep",
0: "monkey",
1: "rooster",
2: "dog",
3: "pig"}
def interpret_western_sign(day, month):
for key in WESTERN_SIGNS:
if month == key[0] and day in key[1]:
return WESTERN_SIGNS[key]
def interpret_chinese_sign(year):
for key in CHINESE_SIGNS:
if year % 12 in CHINESE_SIGNS.keys():
return CHINESE_SIGNS[year % 12]
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month), interpret_chinese_sign(year))