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

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

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

Резултати

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

Код

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

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

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

OK

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

Станислав обнови решението на 08.03.2015 17:17 (преди над 9 години)

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

Решението ти изглежда, че върши работа. Но имам няколко забелжки. Първо - стила. Прочети pep8. Ще бъдем много жестоки към хората, които не ползват 4 интервала. Второ - тези if-ове? Не мислип ли, че са твърде много? Ако зодиите бяха 5000, пак ли щеше да го напишеш така?