Галина обнови решението на 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г.