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

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

Към профила на Георги Любенов

Резултати

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

Код

def interpret_chinese_sign(year):
chinese_zodiac = {
1900: "rat", 1901: "ox", 1902: "tiger", 1903: "rabbit",
1904: "dragon", 1905: "snake",
1906: "horse", 1907: "sheep", 1908: "monkey", 1909: "rooster",
1910: "dog", 1911: "pig"
}
while True:
if year > 1911:
year -= 12
elif year >= 1900 and year <= 1911:
return chinese_zodiac[year]
else:
year += 12
def interpret_western_sign(day, month):
western_zodiac = {
range(101, 121): "capricorn",
range(121, 220): "aquarius", range(220, 321): "pisces",
range(321, 421): "aries", range(421, 521): "taurus",
range(521, 621): "gemini", range(621, 723): "cancer",
range(723, 823): "leo", range(823, 923): "virgo",
range(923, 1023): "libra", range(1023, 1122): "scorpio",
range(1122, 1222): "sagittarius", range(1222, 1232): "capricorn"
}
number = month * 100 + day
for key in western_zodiac:
if number in key:
return western_zodiac[key]
def interpret_both_signs(day, month, year):
str1 = interpret_western_sign(day, month)
str2 = interpret_chinese_sign(year)
result = (str1, str2)
return result
def main():
day = int(input("day>"))
month = int(input("month>"))
year = int(input("year>"))
print(interpret_both_signs(day, month, year))
if __name__ == '__main__':
main()

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

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

OK

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

Георги обнови решението на 05.03.2015 15:21 (преди над 9 години)

+def interpret_western_sign(day, month):
+ if month == 1:
+ if day <= 20:
+ return "capricorn"
+ else:
+ return "aquarius"
+ elif month == 2:
+ if day <= 18:
+ return "aquarius"
+ else:
+ return "pisces"
+ elif month == 3:
+ if day <= 20:
+ return "pisces"
+ else:
+ return "aries"
+ elif month == 4:
+ if day <= 20:
+ return "aries"
+ else:
+ return "taurus"
+ elif month == 5:
+ if day <= 20:
+ return "taurus"
+ else:
+ return "gemini"
+ elif month == 20:
+ if day <= 18:
+ return "gemini"
+ else:
+ return "cancer"
+ elif month == 7:
+ if day <= 22:
+ return "cancer"
+ else:
+ return "leo"
+ elif month == 8:
+ if day <= 22:
+ return "leo"
+ else:
+ return "virgo"
+ elif month == 9:
+ if day <= 22:
+ return "virgo"
+ else:
+ return "libra"
+ elif month == 10:
+ if day <= 22:
+ return "libra"
+ else:
+ return "scorpio"
+ elif month == 11:
+ if day <= 21:
+ return "scorpio"
+ else:
+ return "sagittarius"
+ elif month == 12:
+ if day <= 21:
+ return "sagittarius"
+ else:
+ return "capricorn"
+ else:
+ return "invalid input"
+
+
+def interpret_chinese_sign(year):
+ while True:
+ if year > 1911:
+ year -= 12
+ elif year >= 1900 and year <= 1911:
+ if year == 1900:
+ return "rat"
+ elif year == 1901:
+ return "ox"
+ elif year == 1902:
+ return "tiger"
+ elif year == 1903:
+ return "rabbit"
+ elif year == 1904:
+ return "dragon"
+ elif year == 1905:
+ return "snake"
+ elif year == 1906:
+ return "horse"
+ elif year == 1907:
+ return "sheep"
+ elif year == 1908:
+ return "monkey"
+ elif year == 1909:
+ return "rooster"
+ elif year == 1910:
+ return "dog"
+ elif year == 1911:
+ return "pig"
+ else:
+ year += 12
+
+
+def interpret_both_signs(day, month, year):
+ str1 = interpret_western_sign(day, month)
+ str2 = interpret_chinese_sign(year)
+ result = (str1, str2)
+ return result
+
+
+def main():
+ day = int(input("day>"))
+ month = int(input("month>"))
+ year = int(input("year>"))
+ print(interpret_both_signs(day, month, year))
+
+if __name__ == '__main__':
+ main()

Добре. Виждам, че не те мързи. Това е похвално, но в този случай не е проработило в твоя полза. Да напишеш отеделен if (дори два) за всяка зодия е постижимо ако са 10-20. Както е в този случай. Но, представи си, че зодиите бяха 2500. Щеше ли да имаш отделен if за всяка от тях?

Георги обнови решението на 07.03.2015 00:02 (преди над 9 години)

-def interpret_western_sign(day, month):
- if month == 1:
- if day <= 20:
- return "capricorn"
- else:
- return "aquarius"
- elif month == 2:
- if day <= 18:
- return "aquarius"
- else:
- return "pisces"
- elif month == 3:
- if day <= 20:
- return "pisces"
- else:
- return "aries"
- elif month == 4:
- if day <= 20:
- return "aries"
- else:
- return "taurus"
- elif month == 5:
- if day <= 20:
- return "taurus"
- else:
- return "gemini"
- elif month == 20:
- if day <= 18:
- return "gemini"
- else:
- return "cancer"
- elif month == 7:
- if day <= 22:
- return "cancer"
- else:
- return "leo"
- elif month == 8:
- if day <= 22:
- return "leo"
- else:
- return "virgo"
- elif month == 9:
- if day <= 22:
- return "virgo"
- else:
- return "libra"
- elif month == 10:
- if day <= 22:
- return "libra"
- else:
- return "scorpio"
- elif month == 11:
- if day <= 21:
- return "scorpio"
- else:
- return "sagittarius"
- elif month == 12:
- if day <= 21:
- return "sagittarius"
- else:
- return "capricorn"
- else:
- return "invalid input"
-
-
def interpret_chinese_sign(year):
+ chinese_zodiac = {
+ 1900: "rat", 1901: "ox", 1902: "tiger", 1903: "rabbit",
+ 1904: "dragon", 1905: "snake",
+ 1906: "horse", 1907: "sheep", 1908: "monkey", 1909: "rooster",
+ 1910: "dog", 1911: "pig"
+ }
while True:
if year > 1911:
year -= 12
elif year >= 1900 and year <= 1911:
- if year == 1900:
- return "rat"
- elif year == 1901:
- return "ox"
- elif year == 1902:
- return "tiger"
- elif year == 1903:
- return "rabbit"
- elif year == 1904:
- return "dragon"
- elif year == 1905:
- return "snake"
- elif year == 1906:
- return "horse"
- elif year == 1907:
- return "sheep"
- elif year == 1908:
- return "monkey"
- elif year == 1909:
- return "rooster"
- elif year == 1910:
- return "dog"
- elif year == 1911:
- return "pig"
+ return chinese_zodiac[year]
else:
year += 12
+
+
+def interpret_western_sign(day, month):
+ western_zodiac = {
+ range(101, 121): "capricorn",
+ range(121, 220): "aquarius", range(220, 321): "pisces",
+ range(321, 421): "aries", range(421, 521): "taurus",
+ range(521, 621): "gemini", range(621, 723): "cancer",
+ range(723, 823): "leo", range(823, 923): "virgo",
+ range(923, 1023): "libra", range(1023, 1122): "scorpio",
+ range(1122, 1222): "sagittarius", range(1222, 1232): "capricorn"
+ }
+ number = month * 100 + day
+ for key in western_zodiac:
+ if number in key:
+ return western_zodiac[key]
def interpret_both_signs(day, month, year):
str1 = interpret_western_sign(day, month)
str2 = interpret_chinese_sign(year)
result = (str1, str2)
return result
def main():
day = int(input("day>"))
month = int(input("month>"))
year = int(input("year>"))
print(interpret_both_signs(day, month, year))
if __name__ == '__main__':
main()