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

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

Към профила на Мартин Стоев

Резултати

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

Код

def interpret_western_sign(day, month):
if day <= 0 or day > 31 or month <= 0 or month > 12:
return 'invalid date'
else:
all_signs = [('aries', 3, 21, 31, 4, 20),
('taurus', 4, 21, 30, 5, 20),
('gemini', 5, 21, 31, 6, 20),
('cancer', 6, 21, 30, 7, 22),
('leo', 7, 23, 31, 8, 22),
('virgo', 8, 23, 31, 9, 22),
('libra', 9, 23, 30, 10, 22),
('scorpio', 10, 23, 31, 11, 21),
('sagittarius', 11, 22, 30, 12, 21),
('capricorn', 12, 22, 31, 1, 20),
('aquarius', 1, 21, 31, 2, 19),
('pisces', 2, 19, 29, 3, 20) ]
for sign in all_signs:
if(month == sign[1] and day >= sign[2] and day <= sign[3]) or\
(month == sign[4] and day <= sign[5]):
return sign[0]
def interpret_chinese_sign(year):
sign_index = (year + 8) % 12
all_signs = ['rat' , 'ox' , 'tiger' , 'rabbit' , 'dragon' ,
'snake' , 'horse' , 'sheep' , 'monkey' , 'rooster' ,
'dog' , 'pig']
return all_signs[sign_index]
def interpret_both_signs(day, month, year):
by_year = interpret_chinese_sign(year)
by_month_day = interpret_western_sign(day , month)
return (by_month_day , by_year)

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

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

OK

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

Мартин обнови решението на 10.03.2015 22:04 (преди над 9 години)

+def interpret_western_sign(day, month):
+ if day <= 0 or day > 31 or month <= 0 or month > 12:
+ return 'invalid date'
+ else:
+ all_signs = [ ('aries', 3, 21, 31, 4, 20),
+ ('taurus', 4, 21, 30, 5, 20),
+ ('gemini', 5, 21, 31, 6, 20),
+ ('cancer', 6, 21, 30, 7, 22),
+ ('leo', 7, 23, 31, 8, 22),
+ ('virgo', 8, 23, 31, 9, 22),
+ ('libra', 9, 23, 30, 10, 22),
+ ('scorpio', 10, 23, 31, 11, 21),
+ ('sagittarius', 11, 22, 30, 12, 21),
+ ('capricorn', 12, 22, 31, 1, 20),
+ ('aquarius', 1, 21, 31, 2, 19),
+ ('pisces', 2, 19, 29, 3, 20) ]
+
+ for el in all_signs:
+ if (month == el[1] and day >= el[2] and day <= el[3]) or \
+ (month == el[4] and day <= el[5]):
+ return el[0]
+
+def interpret_chinese_sign(year):
+ x = (year + 8) % 12
+ all_signs = ['rat' , 'ox' , 'tiger' , 'rabbit' , 'dragon' ,
+ 'snake' , 'horse' , 'sheep' , 'monkey' , 'rooster' ,
+ 'dog' , 'pig']
+
+ return all_signs[x]
+
+def interpret_both_signs(day, month, year):
+ by_year = interpret_chinese_sign(year)
+ by_month_day = interpret_western_sign(day , month)
+ return (by_month_day , by_year)

Мартин обнови решението на 10.03.2015 22:06 (преди над 9 години)

def interpret_western_sign(day, month):
- if day <= 0 or day > 31 or month <= 0 or month > 12:
- return 'invalid date'
+ if day <= 0 or day > 31 or month <= 0 or month > 12:
- else:
+ return 'invalid date'
- all_signs = [ ('aries', 3, 21, 31, 4, 20),
+
- ('taurus', 4, 21, 30, 5, 20),
- ('gemini', 5, 21, 31, 6, 20),
- ('cancer', 6, 21, 30, 7, 22),
- ('leo', 7, 23, 31, 8, 22),
- ('virgo', 8, 23, 31, 9, 22),
- ('libra', 9, 23, 30, 10, 22),
- ('scorpio', 10, 23, 31, 11, 21),
- ('sagittarius', 11, 22, 30, 12, 21),
- ('capricorn', 12, 22, 31, 1, 20),
- ('aquarius', 1, 21, 31, 2, 19),
- ('pisces', 2, 19, 29, 3, 20) ]
-
- for el in all_signs:
- if (month == el[1] and day >= el[2] and day <= el[3]) or \
- (month == el[4] and day <= el[5]):
- return el[0]
-
-def interpret_chinese_sign(year):
- x = (year + 8) % 12
- all_signs = ['rat' , 'ox' , 'tiger' , 'rabbit' , 'dragon' ,
- 'snake' , 'horse' , 'sheep' , 'monkey' , 'rooster' ,
- 'dog' , 'pig']
-
- return all_signs[x]
-
-def interpret_both_signs(day, month, year):
- by_year = interpret_chinese_sign(year)
- by_month_day = interpret_western_sign(day , month)
- return (by_month_day , by_year)

Мартин обнови решението на 10.03.2015 22:10 (преди над 9 години)

def interpret_western_sign(day, month):
if day <= 0 or day > 31 or month <= 0 or month > 12:
return 'invalid date'
-
+ else:
+ all_signs = [('aries', 3, 21, 31, 4, 20),
+ ('taurus', 4, 21, 30, 5, 20),
+ ('gemini', 5, 21, 31, 6, 20),
+ ('cancer', 6, 21, 30, 7, 22),
+ ('leo', 7, 23, 31, 8, 22),
+ ('virgo', 8, 23, 31, 9, 22),
+ ('libra', 9, 23, 30, 10, 22),
+ ('scorpio', 10, 23, 31, 11, 21),
+ ('sagittarius', 11, 22, 30, 12, 21),
+ ('capricorn', 12, 22, 31, 1, 20),
+ ('aquarius', 1, 21, 31, 2, 19),
+ ('pisces', 2, 19, 29, 3, 20) ]
+
+ for el in all_signs:
+ if (month == el[1] and day >= el[2] and day <= el[3]) or \
+ (month == el[4] and day <= el[5]):
+ return el[0]
+
+def interpret_chinese_sign(year):
+ x = (year + 8) % 12
+ all_signs = ['rat' , 'ox' , 'tiger' , 'rabbit' , 'dragon' ,
+ 'snake' , 'horse' , 'sheep' , 'monkey' , 'rooster' ,
+ 'dog' , 'pig']
+ return all_signs[x]
+
+def interpret_both_signs(day, month, year):
+ by_year = interpret_chinese_sign(year)
+ by_month_day = interpret_western_sign(day , month)
+ return (by_month_day , by_year)

Мартин обнови решението на 11.03.2015 13:58 (преди над 9 години)

def interpret_western_sign(day, month):
if day <= 0 or day > 31 or month <= 0 or month > 12:
return 'invalid date'
else:
all_signs = [('aries', 3, 21, 31, 4, 20),
('taurus', 4, 21, 30, 5, 20),
('gemini', 5, 21, 31, 6, 20),
('cancer', 6, 21, 30, 7, 22),
('leo', 7, 23, 31, 8, 22),
('virgo', 8, 23, 31, 9, 22),
('libra', 9, 23, 30, 10, 22),
('scorpio', 10, 23, 31, 11, 21),
('sagittarius', 11, 22, 30, 12, 21),
('capricorn', 12, 22, 31, 1, 20),
('aquarius', 1, 21, 31, 2, 19),
('pisces', 2, 19, 29, 3, 20) ]
- for el in all_signs:
- if (month == el[1] and day >= el[2] and day <= el[3]) or \
- (month == el[4] and day <= el[5]):
- return el[0]
+ for sign in all_signs:
+ if(month == sign[1] and day >= sign[2] and day <= sign[3]) or\
+ (month == sign[4] and day <= sign[5]):
+ return sign[0]
+
def interpret_chinese_sign(year):
- x = (year + 8) % 12
+ sign_index = (year + 8) % 12
all_signs = ['rat' , 'ox' , 'tiger' , 'rabbit' , 'dragon' ,
'snake' , 'horse' , 'sheep' , 'monkey' , 'rooster' ,
'dog' , 'pig']
- return all_signs[x]
+ return all_signs[sign_index]
+
def interpret_both_signs(day, month, year):
by_year = interpret_chinese_sign(year)
by_month_day = interpret_western_sign(day , month)
return (by_month_day , by_year)