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

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

Към профила на Спасимир Нонев

Резултати

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

Код

def interpret_western_sign(day, month):
if (21 <= day <= 31 and month == 3) or (1 <= day <= 20 and month == 4):
return 'aries'
elif (21 <= day <= 30 and month == 4) or (1 <= day <= 20 and month == 5):
return 'taurus'
elif (21 <= day <= 31 and month == 5) or (1 <= day <= 20 and month == 6):
return 'gemini'
elif (21 <= day <= 30 and month == 6) or (1 <= day <= 22 and month == 7):
return 'cancer'
elif (23 <= day <= 31 and month == 7) or (1 <= day <= 22 and month == 8):
return 'leo'
elif (23 <= day <= 31 and month == 8) or (1 <= day <= 22 and month == 9):
return 'virgo'
elif (23 <= day <= 30 and month == 9) or (1 <= day <= 22 and month == 10):
return 'libra'
elif (23 <= day <= 31 and month == 10) or (1 <= day <= 21 and month == 11):
return 'scorpio'
elif (22 <= day <= 30 and month == 11) or (1 <= day <= 21 and month == 12):
return 'sagittarius'
elif (22 <= day <= 31 and month == 12) or (1 <= day <= 20 and month == 1):
return 'capricorn'
elif (21 <= day <= 31 and month == 1) or (1 <= day <= 18 and month == 2):
return 'aquarius'
elif (19 <= day <= 29 and month == 2) or (1 <= day <= 20 and month == 3):
return 'pisces'
def interpret_chinese_sign(year):
chinese_sign = ('monkey', 'rooster', 'dog', 'pig',
'rat', 'ox', 'tiger',
'rabbit', 'dragon', 'snake',
'horse', 'sheep')
return chinese_sign[year % 12]
def interpret_both_signs(day, month, year):
return interpret_western_sign(day, month), interpret_chinese_sign(year)

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

......
----------------------------------------------------------------------
Ran 6 tests in 0.007s

OK

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

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

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

Спасимир обнови решението на 09.03.2015 23:23 (преди над 9 години)

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

Виж колко хубаво си ползвал някаква структура от данни за да си организираш зодиите в interpret_chinese_sign. Пробвай се да измислиш нещо по добро за interpret_western_sign. Тея if-ове са прекалено неприложими ако зодиите бяха повече..

Също така речник с ключове последователни цели числа? Има нещо готово, което индексира по същия начин.

Спасимир обнови решението на 11.03.2015 00:14 (преди над 9 години)

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