Решение на Астрологични забави от Галина Димитрова

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

Към профила на Галина Димитрова

Резултати

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

Код

def find_west_sign(begin_sign, end_sign, day_of_change, day):
if day <= day_of_change:
return begin_sign
else:
return end_sign
# solution with dictionary
def interpret_western_sign(day, month):
# can be done with arrey too, where the index for the info
# of the given month will be month - 1
west_sign_dict = {
1: ("capricorn", "aquarius", 20),
2: ("aquarius", "pisces", 18),
3: ("pisces", "aries", 20),
4: ("aries", "taurus", 20),
5: ("taurus", "gemini", 20),
6: ("gemini", "cancer", 20),
7: ("cancer", "leo", 22),
8: ("leo", "virgo", 22),
9: ("virgo", "libra", 22),
10: ("libra", "scorpio", 22),
11: ("scorpio", "sagittarius", 21),
12: ("sagittarius", "capricorn", 21)
}
begin_sign = west_sign_dict[month][0]
end_sign = west_sign_dict[month][1]
day_of_change = west_sign_dict[month][2]
return find_west_sign(begin_sign, end_sign, day_of_change, day)
# solution with arrey
def interpret_chinese_sign(year):
chinese_signs = ["monkey", "rooster", "dog", "pig", "rat", "ox",
"tiger", "rabbit", "dragon", "snake", "horse", "sheep"]
# changed 12 to be the length of the arrey
return chinese_signs[year % len(chinese_signs)]
def interpret_both_signs(day, month, year):
west_sign = interpret_western_sign(day, month)
chinese_sign = interpret_chinese_sign(year)
# makes the tuple...
both_signs = (west_sign, chinese_sign)
return both_signs

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

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

OK

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

Галина обнови решението на 06.03.2015 22:04 (преди над 9 години)

+def january(day):
+ if day <= 20:
+ return "capricorn"
+ else:
+ return "aquarius"
+
+
+def february(day):
+ if day <= 18:
+ return "aquarius"
+ else:
+ return "pisces"
+
+
+def march(day):
+ if day <= 20:
+ return "pisces"
+ else:
+ return "aries"
+
+
+def april(day):
+ if day <= 20:
+ return "aries"
+ else:
+ return "taurus"
+
+
+def may(day):
+ if day <= 20:
+ return "taurus"
+ else:
+ return "gemini"
+
+
+def june(day):
+ if day <= 20:
+ return "gemini"
+ else:
+ return "cancer"
+
+
+def july(day):
+ if day <= 22:
+ return "cancer"
+ else:
+ return "leo"
+
+
+def august(day):
+ if day <= 22:
+ return "leo"
+ else:
+ return "virgo"
+
+
+def september(day):
+ if day <= 22:
+ return "virgo"
+ else:
+ return "libra"
+
+
+def october(day):
+ if day <= 22:
+ return "libra"
+ else:
+ return "scorpio"
+
+
+def november(day):
+ if day <= 21:
+ return "scorpio"
+ else:
+ return "sagittarius"
+
+
+def december(day):
+ if day <= 21:
+ return "sagittarius"
+ else:
+ return "capricorn"
+
+
+# solution with dictionary
+def interpret_western_sign(day, month):
+ west_sign_dict = {
+ 1: january(day),
+ 2: february(day),
+ 3: march(day),
+ 4: april(day),
+ 5: may(day),
+ 6: june(day),
+ 7: july(day),
+ 8: august(day),
+ 9: september(day),
+ 10: october(day),
+ 11: november(day),
+ 12: december(day)
+ }
+
+ return west_sign_dict[month]
+
+
+# solution without dictionary
+def interpret_western_sign2(day, month):
+ sign = ""
+ if month == 1:
+ sign = january(day)
+ elif month == 2:
+ sign = february(day)
+ elif month == 3:
+ sign = march(day)
+ elif month == 4:
+ sign = april(day)
+ elif month == 5:
+ sign = may(day)
+ elif month == 6:
+ sign = june(day)
+ elif month == 7:
+ sign = july(day)
+ elif month == 8:
+ sign = august(day)
+ elif month == 9:
+ sign = september(day)
+ elif month == 10:
+ sign = october(day)
+ elif month == 11:
+ sign = november(day)
+ elif month == 12:
+ sign = december(day)
+
+ return sign
+
+
+# takes the given year and makes it in range(1900 - 1911),
+# in which we know (year: sign)
+def make_year_in_known_range(year):
+ while year < 1900 or year > 1911:
+ if year < 1900:
+ year += 12
+ else:
+ year -= 12
+ return year
+
+
+# solution with dictionary
+def interpret_chinese_sign(year):
+ known_year = make_year_in_known_range(year)
+ signs_dict = {
+ 1900: "rat",
+ 1901: "ox",
+ 1902: "tiger",
+ 1903: "rabbit",
+ 1904: "dragon",
+ 1905: "snake",
+ 1906: "horse",
+ 1907: "sheep",
+ 1908: "monkey",
+ 1909: "rooster",
+ 1910: "dog",
+ 1911: "pig"
+ }
+
+ return signs_dict[known_year]
+
+
+# solution wothout using dictionary
+def interpret_chinese_sign2(year):
+ known_year = make_year_in_known_range(year)
+
+ if known_year == 1900:
+ return "rat"
+ elif known_year == 1901:
+ return "ox"
+ elif known_year == 1902:
+ return "tiger"
+ elif known_year == 1903:
+ return "rabbit"
+ elif known_year == 1904:
+ return "dragon"
+ elif known_year == 1905:
+ return "snake"
+ elif known_year == 1906:
+ return "horse"
+ elif known_year == 1907:
+ return "sheep"
+ elif known_year == 1908:
+ return "monkey"
+ elif known_year == 1909:
+ return "rooster"
+ elif known_year == 1910:
+ return "dog"
+ elif known_year == 1911:
+ return "pig"
+
+
+def interpret_both_signs(day, month, year):
+ west_sign = interpret_western_sign(day, month)
+ chinese_sign = interpret_chinese_sign(year)
+ # makes the tuple...
+ both_signs = (west_sign, chinese_sign)
+
+ return both_signs

Първо - много ми харесва, че си разделила прблема на по - малки проблеми. Това е правилния начин за конструиране на програма. В случая, обаче, е прекалено много.

Намирането ти на западни зодии е доста сложно. Ако зодиите бяха 5000 щеше ли да го направиш по този начин? Или ако годината се състоеше от 55 месеца? Щеше ли да напишеш 55 еднакви функции?

make_year_in_known_range може отнеме доста време. Пробвай го с годината 42 ** 42. Може да е в бъдещето, но е съвсем разумно да попитам коя китайска зодия ще е човек, роден през 150130937545296572356771972164254457814047970568738777235893533016064г.

Галина обнови решението на 10.03.2015 09:20 (преди над 9 години)

-def january(day):
- if day <= 20:
- return "capricorn"
+def find_west_sign(begin_sign, end_sign, day_of_change, day):
+ if day <= day_of_change:
+ return begin_sign
else:
- return "aquarius"
+ return end_sign
-def february(day):
- if day <= 18:
- return "aquarius"
- else:
- return "pisces"
-
-
-def march(day):
- if day <= 20:
- return "pisces"
- else:
- return "aries"
-
-
-def april(day):
- if day <= 20:
- return "aries"
- else:
- return "taurus"
-
-
-def may(day):
- if day <= 20:
- return "taurus"
- else:
- return "gemini"
-
-
-def june(day):
- if day <= 20:
- return "gemini"
- else:
- return "cancer"
-
-
-def july(day):
- if day <= 22:
- return "cancer"
- else:
- return "leo"
-
-
-def august(day):
- if day <= 22:
- return "leo"
- else:
- return "virgo"
-
-
-def september(day):
- if day <= 22:
- return "virgo"
- else:
- return "libra"
-
-
-def october(day):
- if day <= 22:
- return "libra"
- else:
- return "scorpio"
-
-
-def november(day):
- if day <= 21:
- return "scorpio"
- else:
- return "sagittarius"
-
-
-def december(day):
- if day <= 21:
- return "sagittarius"
- else:
- return "capricorn"
-
-
# solution with dictionary
def interpret_western_sign(day, month):
west_sign_dict = {
- 1: january(day),
- 2: february(day),
- 3: march(day),
- 4: april(day),
- 5: may(day),
- 6: june(day),
- 7: july(day),
- 8: august(day),
- 9: september(day),
- 10: october(day),
- 11: november(day),
- 12: december(day)
+ 1: ("capricorn", "aquarius", 20),
+ 2: ("aquarius", "pisces", 18),
+ 3: ("pisces", "aries", 20),
+ 4: ("aries", "taurus", 20),
+ 5: ("taurus", "gemini", 20),
+ 6: ("gemini", "cancer", 20),
+ 7: ("cancer", "leo", 22),
+ 8: ("leo", "virgo", 22),
+ 9: ("virgo", "libra", 22),
+ 10: ("libra", "scorpio", 22),
+ 11: ("scorpio", "sagittarius", 21),
+ 12: ("sagittarius", "capricorn", 21)
}
+ begin_sign = west_sign_dict[month][0]
+ end_sign = west_sign_dict[month][1]
+ day_of_change = west_sign_dict[month][2]
- return west_sign_dict[month]
+ return find_west_sign(begin_sign, end_sign, day_of_change, day)
-# solution without dictionary
-def interpret_western_sign2(day, month):
- sign = ""
- if month == 1:
- sign = january(day)
- elif month == 2:
- sign = february(day)
- elif month == 3:
- sign = march(day)
- elif month == 4:
- sign = april(day)
- elif month == 5:
- sign = may(day)
- elif month == 6:
- sign = june(day)
- elif month == 7:
- sign = july(day)
- elif month == 8:
- sign = august(day)
- elif month == 9:
- sign = september(day)
- elif month == 10:
- sign = october(day)
- elif month == 11:
- sign = november(day)
- elif month == 12:
- sign = december(day)
-
- return sign
-
-
-# takes the given year and makes it in range(1900 - 1911),
-# in which we know (year: sign)
-def make_year_in_known_range(year):
- while year < 1900 or year > 1911:
- if year < 1900:
- year += 12
- else:
- year -= 12
- return year
-
-
-# solution with dictionary
+# solution with arrey
def interpret_chinese_sign(year):
- known_year = make_year_in_known_range(year)
- signs_dict = {
- 1900: "rat",
- 1901: "ox",
- 1902: "tiger",
- 1903: "rabbit",
- 1904: "dragon",
- 1905: "snake",
- 1906: "horse",
- 1907: "sheep",
- 1908: "monkey",
- 1909: "rooster",
- 1910: "dog",
- 1911: "pig"
- }
+ chinese_signs = ["monkey", "rooster", "dog", "pig", "rat", "ox",
+ "tiger", "rabbit", "dragon", "snake", "horse", "sheep"]
- return signs_dict[known_year]
-
-
-# solution wothout using dictionary
-def interpret_chinese_sign2(year):
- known_year = make_year_in_known_range(year)
-
- if known_year == 1900:
- return "rat"
- elif known_year == 1901:
- return "ox"
- elif known_year == 1902:
- return "tiger"
- elif known_year == 1903:
- return "rabbit"
- elif known_year == 1904:
- return "dragon"
- elif known_year == 1905:
- return "snake"
- elif known_year == 1906:
- return "horse"
- elif known_year == 1907:
- return "sheep"
- elif known_year == 1908:
- return "monkey"
- elif known_year == 1909:
- return "rooster"
- elif known_year == 1910:
- return "dog"
- elif known_year == 1911:
- return "pig"
+ return chinese_signs[year % 12]
def interpret_both_signs(day, month, year):
west_sign = interpret_western_sign(day, month)
chinese_sign = interpret_chinese_sign(year)
# makes the tuple...
both_signs = (west_sign, chinese_sign)
return both_signs

Галина обнови решението на 10.03.2015 09:26 (преди над 9 години)

def find_west_sign(begin_sign, end_sign, day_of_change, day):
if day <= day_of_change:
return begin_sign
else:
return end_sign
# solution with dictionary
def interpret_western_sign(day, month):
+ # can be done with arrey too, where the index for the info
+ # of the given month will be month - 1
west_sign_dict = {
1: ("capricorn", "aquarius", 20),
2: ("aquarius", "pisces", 18),
3: ("pisces", "aries", 20),
4: ("aries", "taurus", 20),
5: ("taurus", "gemini", 20),
6: ("gemini", "cancer", 20),
7: ("cancer", "leo", 22),
8: ("leo", "virgo", 22),
9: ("virgo", "libra", 22),
10: ("libra", "scorpio", 22),
11: ("scorpio", "sagittarius", 21),
12: ("sagittarius", "capricorn", 21)
}
begin_sign = west_sign_dict[month][0]
end_sign = west_sign_dict[month][1]
day_of_change = west_sign_dict[month][2]
return find_west_sign(begin_sign, end_sign, day_of_change, day)
# solution with arrey
def interpret_chinese_sign(year):
chinese_signs = ["monkey", "rooster", "dog", "pig", "rat", "ox",
"tiger", "rabbit", "dragon", "snake", "horse", "sheep"]
- return chinese_signs[year % 12]
+ # changed 12 to be the length of the arrey
+ return chinese_signs[year % len(chinese_signs)]
def interpret_both_signs(day, month, year):
west_sign = interpret_western_sign(day, month)
chinese_sign = interpret_chinese_sign(year)
# makes the tuple...
both_signs = (west_sign, chinese_sign)
return both_signs