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

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

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

Резултати

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

Код

def interpret_western_sign(day, month):
if month == 1:
if day > 0 and day <= 20:
return "capricorn"
if day >= 21 and day <= 30:
return "aquarius"
if month == 2:
if day > 0 and day <= 19:
return "aquarius"
if day >= 20 and day < 30:
return "pisces"
if month == 3:
if day > 0 and day <= 20:
return "pisces"
if day >= 21 and day <= 30:
return "aries"
if month == 4:
if day > 0 and day <= 20:
return "aries"
if day >= 21 and day <= 30:
return "taurus"
if month == 5:
if day > 0 and day <= 20:
return "taurus"
if day >= 21 and day <= 30:
return "gemini"
if month == 6:
if day > 0 and day <= 20:
return "gemini"
if day >= 21 and day <= 30:
return "cancer"
if month == 7:
if day > 0 and day <= 22:
return "cancer"
if day >= 23 and day <= 30:
return "leo"
if month == 8:
if day > 0 and day <= 22:
return "leo"
if day >= 23 and day <= 30:
return "virgo"
if month == 9:
if day > 0 and day <= 22:
return "virgo"
if day >= 23 and day <= 30:
return "libra"
if month == 10:
if day > 0 and day <= 22:
return "libra"
if day >= 23 and day <= 30:
return "scorpio"
if month == 11:
if day > 0 and day <= 21:
return "scorpio"
if day >= 22 and day <= 30:
return "sagittarius"
if month == 12:
if day > 0 and day <= 21:
return "sagittarius"
if day >= 22 and day <= 30:
return "capricorn"
def interpret_chinese_sign(year):
reminder = year % 12
if reminder == 1900 % 12:
return "rat"
if reminder == 1901 % 12:
return "ox"
if reminder == 1902 % 12:
return "tiger"
if reminder == 1903 % 12:
return "rabbit"
if reminder == 1904 % 12:
return "dragon"
if reminder == 1905 % 12:
return "snake"
if reminder == 1906 % 12:
return "horse"
if reminder == 1907 % 12:
return "sheep"
if reminder == 1908 % 12:
return "monkey"
if reminder == 1909 % 12:
return "rooster"
if reminder == 1910 % 12:
return "dog"
if reminder == 1911 % 12:
return "pig"
def interpret_both_signs(day, month, year):
return interpret_western_sign(day, month), interpret_chinese_sign(year)
# print (interpret_both_signs(23, 12, 1832))

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

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

OK

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

Стоян обнови решението на 09.03.2015 20:49 (преди над 9 години)

+def interpret_western_sign(day, month):
+ if month == 1:
+ if day > 0 and day <= 20:
+ return "capricorn"
+ if day >= 21 and day <= 30:
+ return "aquarius"
+ if month == 2:
+ if day > 0 and day <= 19:
+ return "aquarius"
+ if day >= 20 and day < 30:
+ return "pisces"
+ if month == 3:
+ if day > 0 and day <=20:
+ return "pisces"
+ if day >= 21 and day <= 30:
+ return "aries"
+ if month == 4:
+ if day > 0 and day <= 20:
+ return "aries"
+ if day >= 21 and day <= 30:
+ return "taurus"
+ if month == 5:
+ if day > 0 and day <= 20:
+ return "taurus"
+ if day >= 21 and day <= 30:
+ return "gemini"
+ if month == 6:
+ if day > 0 and day <= 20:
+ return "gemini"
+ if day >= 21 and day <= 30:
+ return "cancer"
+ if month == 7:
+ if day > 0 and day <= 22:
+ return "cancer"
+ if day >= 23 and day <=30:
+ return "leo"
+ if month == 8:
+ if day > 0 and day <= 22:
+ return "leo"
+ if day >= 23 and day <= 30:
+ return "virgo"
+ if month == 9:
+ if day > 0 and day <= 22:
+ return "virgo"
+ if day >= 23 and day <= 30:
+ return "libra"
+ if month == 10:
+ if day > 0 and day <= 22:
+ return "libra"
+ if day >= 23 and day <= 30:
+ return "scorpio"
+ if month == 11:
+ if day > 0 and day <= 21:
+ return "scorpio"
+ if day >= 22 and day <= 30:
+ return "sagittarius"
+ if month == 12:
+ if day > 0 and day <= 21:
+ return "sagittarius"
+ if day >= 22 and day <= 30:
+ return "capricorn"
+
+def interpret_chinese_sign(year):
+ reminder = year % 12
+ if reminder == 1900 % 12:
+ return "rat"
+ if reminder == 1901 % 12:
+ return "ox"
+ if reminder == 1902 % 12:
+ return "tiger"
+ if reminder == 1903 % 12:
+ return "rabbit"
+ if reminder == 1904 % 12:
+ return "dragon"
+ if reminder == 1905 % 12:
+ return "snake"
+ if reminder == 1906 % 12:
+ return "horse"
+ if reminder == 1907 % 12:
+ return "sheep"
+ if reminder == 1908 % 12:
+ return "monkey"
+ if reminder == 1909 % 12:
+ return "rooster"
+ if reminder == 1910 % 12:
+ return "dog"
+ if reminder == 1911 % 12:
+ return "pig"
+
+def interpret_both_signs(day, month, year):
+ result = interpret_western_sign( day, month), interpret_chinese_sign(year)
+ return result
+
+#print (interpret_both_signs(23, 12, 1832))
  • бързо да оправиш тея интервали от по 8 спейса. Трябва да са 4 - четири. Рискуваш да ти бъдат отнети точки, ако оставиш решението така.
  • отделяй глобално дефинираните функции с 2 празни реда
  • пробвай се да измислиш нещо по-хитро, може би ползващо някоя структура от данни, за да организираш зодиите. Ако имаше 500 зодии пак ли щеше да пишеш if-ове?
  • няма нужда да правиш тази променлива result
  • впрочем ред 91 е по-дълъг от 79 символа [а не трябва] (https://www.python.org/dev/peps/pep-0008/#maximum-line-length)
  • на ред 36 и 77 имаш ненужни интервали в края на реда
  • на ред 13, 35 нямаш интервали след операторите <=
  • на ред 91 имаш ненужен интервал пред day

Как разбрах за последните 4? С набито око или добре нагласен едитор - ти познай. Отдели време да си нагласиш едитора, няма да съжеляваш!

Стоян обнови решението на 11.03.2015 12:19 (преди над 9 години)

def interpret_western_sign(day, month):
- if month == 1:
- if day > 0 and day <= 20:
- return "capricorn"
- if day >= 21 and day <= 30:
- return "aquarius"
- if month == 2:
- if day > 0 and day <= 19:
- return "aquarius"
- if day >= 20 and day < 30:
- return "pisces"
- if month == 3:
- if day > 0 and day <=20:
- return "pisces"
- if day >= 21 and day <= 30:
- return "aries"
- if month == 4:
- if day > 0 and day <= 20:
- return "aries"
- if day >= 21 and day <= 30:
- return "taurus"
- if month == 5:
- if day > 0 and day <= 20:
- return "taurus"
- if day >= 21 and day <= 30:
- return "gemini"
- if month == 6:
- if day > 0 and day <= 20:
- return "gemini"
- if day >= 21 and day <= 30:
- return "cancer"
- if month == 7:
- if day > 0 and day <= 22:
- return "cancer"
- if day >= 23 and day <=30:
- return "leo"
- if month == 8:
- if day > 0 and day <= 22:
- return "leo"
- if day >= 23 and day <= 30:
- return "virgo"
- if month == 9:
- if day > 0 and day <= 22:
- return "virgo"
- if day >= 23 and day <= 30:
- return "libra"
- if month == 10:
- if day > 0 and day <= 22:
- return "libra"
- if day >= 23 and day <= 30:
- return "scorpio"
- if month == 11:
- if day > 0 and day <= 21:
- return "scorpio"
- if day >= 22 and day <= 30:
- return "sagittarius"
- if month == 12:
- if day > 0 and day <= 21:
- return "sagittarius"
- if day >= 22 and day <= 30:
- return "capricorn"
+ if month == 1:
+ if day > 0 and day <= 20:
+ return "capricorn"
+ if day >= 21 and day <= 30:
+ return "aquarius"
+ if month == 2:
+ if day > 0 and day <= 19:
+ return "aquarius"
+ if day >= 20 and day < 30:
+ return "pisces"
+ if month == 3:
+ if day > 0 and day <= 20:
+ return "pisces"
+ if day >= 21 and day <= 30:
+ return "aries"
+ if month == 4:
+ if day > 0 and day <= 20:
+ return "aries"
+ if day >= 21 and day <= 30:
+ return "taurus"
+ if month == 5:
+ if day > 0 and day <= 20:
+ return "taurus"
+ if day >= 21 and day <= 30:
+ return "gemini"
+ if month == 6:
+ if day > 0 and day <= 20:
+ return "gemini"
+ if day >= 21 and day <= 30:
+ return "cancer"
+ if month == 7:
+ if day > 0 and day <= 22:
+ return "cancer"
+ if day >= 23 and day <= 30:
+ return "leo"
+ if month == 8:
+ if day > 0 and day <= 22:
+ return "leo"
+ if day >= 23 and day <= 30:
+ return "virgo"
+ if month == 9:
+ if day > 0 and day <= 22:
+ return "virgo"
+ if day >= 23 and day <= 30:
+ return "libra"
+ if month == 10:
+ if day > 0 and day <= 22:
+ return "libra"
+ if day >= 23 and day <= 30:
+ return "scorpio"
+ if month == 11:
+ if day > 0 and day <= 21:
+ return "scorpio"
+ if day >= 22 and day <= 30:
+ return "sagittarius"
+ if month == 12:
+ if day > 0 and day <= 21:
+ return "sagittarius"
+ if day >= 22 and day <= 30:
+ return "capricorn"
+
def interpret_chinese_sign(year):
- reminder = year % 12
- if reminder == 1900 % 12:
- return "rat"
- if reminder == 1901 % 12:
- return "ox"
- if reminder == 1902 % 12:
- return "tiger"
- if reminder == 1903 % 12:
- return "rabbit"
- if reminder == 1904 % 12:
- return "dragon"
- if reminder == 1905 % 12:
- return "snake"
- if reminder == 1906 % 12:
- return "horse"
- if reminder == 1907 % 12:
- return "sheep"
- if reminder == 1908 % 12:
- return "monkey"
- if reminder == 1909 % 12:
- return "rooster"
- if reminder == 1910 % 12:
- return "dog"
- if reminder == 1911 % 12:
- return "pig"
+ reminder = year % 12
+ if reminder == 1900 % 12:
+ return "rat"
+ if reminder == 1901 % 12:
+ return "ox"
+ if reminder == 1902 % 12:
+ return "tiger"
+ if reminder == 1903 % 12:
+ return "rabbit"
+ if reminder == 1904 % 12:
+ return "dragon"
+ if reminder == 1905 % 12:
+ return "snake"
+ if reminder == 1906 % 12:
+ return "horse"
+ if reminder == 1907 % 12:
+ return "sheep"
+ if reminder == 1908 % 12:
+ return "monkey"
+ if reminder == 1909 % 12:
+ return "rooster"
+ if reminder == 1910 % 12:
+ return "dog"
+ if reminder == 1911 % 12:
+ return "pig"
+
def interpret_both_signs(day, month, year):
- result = interpret_western_sign( day, month), interpret_chinese_sign(year)
- return result
+ result = interpret_western_sign(day, month), interpret_chinese_sign(year)
+ return result
-#print (interpret_both_signs(23, 12, 1832))
+ # print (interpret_both_signs(23, 12, 1832))

Стоян обнови решението на 11.03.2015 12:23 (преди над 9 години)

def interpret_western_sign(day, month):
if month == 1:
if day > 0 and day <= 20:
return "capricorn"
if day >= 21 and day <= 30:
return "aquarius"
if month == 2:
if day > 0 and day <= 19:
return "aquarius"
if day >= 20 and day < 30:
return "pisces"
if month == 3:
if day > 0 and day <= 20:
return "pisces"
if day >= 21 and day <= 30:
return "aries"
if month == 4:
if day > 0 and day <= 20:
return "aries"
if day >= 21 and day <= 30:
return "taurus"
if month == 5:
if day > 0 and day <= 20:
return "taurus"
if day >= 21 and day <= 30:
return "gemini"
if month == 6:
if day > 0 and day <= 20:
return "gemini"
if day >= 21 and day <= 30:
return "cancer"
if month == 7:
if day > 0 and day <= 22:
return "cancer"
if day >= 23 and day <= 30:
return "leo"
if month == 8:
if day > 0 and day <= 22:
return "leo"
if day >= 23 and day <= 30:
return "virgo"
if month == 9:
if day > 0 and day <= 22:
return "virgo"
if day >= 23 and day <= 30:
return "libra"
if month == 10:
if day > 0 and day <= 22:
return "libra"
if day >= 23 and day <= 30:
return "scorpio"
if month == 11:
if day > 0 and day <= 21:
return "scorpio"
if day >= 22 and day <= 30:
return "sagittarius"
if month == 12:
if day > 0 and day <= 21:
return "sagittarius"
if day >= 22 and day <= 30:
return "capricorn"
def interpret_chinese_sign(year):
reminder = year % 12
if reminder == 1900 % 12:
return "rat"
if reminder == 1901 % 12:
return "ox"
if reminder == 1902 % 12:
return "tiger"
if reminder == 1903 % 12:
return "rabbit"
if reminder == 1904 % 12:
return "dragon"
if reminder == 1905 % 12:
return "snake"
if reminder == 1906 % 12:
return "horse"
if reminder == 1907 % 12:
return "sheep"
if reminder == 1908 % 12:
return "monkey"
if reminder == 1909 % 12:
return "rooster"
if reminder == 1910 % 12:
return "dog"
if reminder == 1911 % 12:
return "pig"
def interpret_both_signs(day, month, year):
- result = interpret_western_sign(day, month), interpret_chinese_sign(year)
- return result
+ return interpret_western_sign(day, month), interpret_chinese_sign(year)
+
# print (interpret_both_signs(23, 12, 1832))