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

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

Към профила на Калоян Витанов

Резултати

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

Код

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

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

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

OK

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

Калоян обнови решението на 08.03.2015 22:01 (преди над 9 години)

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

Калоян обнови решението на 08.03.2015 22:07 (преди над 9 години)

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

Имам няколко забележки за стила ти.

Ако западните зодиите бяха 5000? Щеше ли да напишеш 5000 if-a? Не мислиш ли, че функцията за китайските зодии е прекалено сложна? Също така, прочети по - внимателно как се предава домашно. Наблегни на pep8.

Калоян обнови решението на 09.03.2015 22:37 (преди над 9 години)

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

Дойчине, благодаря за забележките ти! :) Изглежда бях разбрал погрешно някои от нещата в pep8, сега мисля съм оправил нещата. Ако зодиите бяха 5000 щях да помисля за друг начин. Впрочем даже и за 12-те помислих за друг начин, но понеже не съм програмирал нищо от доста време (аз съм ПМ 4-ти курс) и съм позабравил нещата, не се сетих и се задоволих с този. Напълно наложително ли е да направя нещата по друг начин и ако да може ли някакъв hint коя структура евентуално би свършила работа? Какво по- точно не харесваш във функцията за китайските зодии? Ако изключим предишната забележка като възможност то не съм сигурен, че те разбирам.