Решение на Астрологични забави от Деян Боиклиев

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

Към профила на Деян Боиклиев

Резултати

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

Код

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

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

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

OK

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

Деян обнови решението на 07.03.2015 22:19 (преди над 9 години)

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

Деян обнови решението на 07.03.2015 22:20 (преди над 9 години)

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

Деян обнови решението на 07.03.2015 22:28 (преди над 9 години)

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

Деян обнови решението на 07.03.2015 22:34 (преди над 9 години)

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

Деян обнови решението на 07.03.2015 22:54 (преди над 9 години)

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

Работи, само няколко забележки:

  • аз бих изнесал всички константи най-отгоре на файла
  • имаш ред по-дълъг от 79 символа. Разбии го на няколко реда.
  • поставяш интервали пред и след : в речниците. Трябва да поставяш такива само след:

       WESTERN_SIGNS_BY_MONTH = {
         1: {(1, 20): "capricorn", (21, 31): "aquarius"},
         2: {(1, 18): "aquarius", (19, 29): "pisces"},
       ......
       } 
    

Деян обнови решението на 08.03.2015 12:27 (преди над 9 години)

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

Деян обнови решението на 08.03.2015 15:51 (преди над 9 години)

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