Решение на Астрологични забави от Никола Шахпазов

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

Към профила на Никола Шахпазов

Резултати

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

Код

import datetime
from intervaltree import Interval, IntervalTree
signs = IntervalTree()
signs[80:110] = "aries"
signs[111:140] = "taurus"
signs[141:171] = "gemini"
signs[172:203] = "cancer"
signs[204:234] = "leo"
signs[235:265] = "virgo"
signs[266:295] = "libra"
signs[296:325] = "scorpio"
signs[326:355] = "sagittarius"
signs[0:20] = "capricorn"
signs[21:50] = "aquarius"
signs[51:79] = "pisces"
# task1
def interpret_western_sign(day, month):
year_day = datetime.date(2015, month, day).timetuple().tm_yday
if year_day == 356:
year_day = 0
return sorted(signs[year_day])[0].data
chinese_signs = [
"rat",
"ox",
"tiger",
"rabbit",
"dragon",
"snake",
"horse",
"sheep",
"monkey",
"rooster",
"dog",
"pig"
]
# task 2
def interpret_chinese_sign(year):
index = (year - 1900) % 12
return chinese_signs[index]
# task 3
def interpret_both_signs(day, month, year):
western = interpret_western_sign(day, month)
chin = interpret_chinese_sign(year)
return (western, chin)

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

No module named 'intervaltree'
  File "lib/language/python/runner.py", line 102, in main
    test = imp.load_source('test', test_module)
  File "/home/pyfmi/Python-3.4.2/Lib/imp.py", line 171, in load_source
    module = methods.load()
  File "<frozen importlib._bootstrap>", line 1220, in load
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/tmp/d20150312-24164-qzurzd/test.py", line 2, in <module>
    import solution
  File "/tmp/d20150312-24164-qzurzd/solution.py", line 2, in <module>
    from intervaltree import Interval, IntervalTree

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

Никола обнови решението на 11.03.2015 00:25 (преди над 9 години)

+import datetime
+from intervaltree import Interval, IntervalTree
+signs = IntervalTree()
+
+signs[80:110] = "aries"
+signs[111:140] = "taurus"
+signs[141:171] = "gemini"
+signs[172:203] = "cancer"
+signs[204:234] = "leo"
+signs[235:265] = "virgo"
+signs[266:295] = "libra"
+signs[296:325] = "scorpio"
+signs[326:355] = "sagittarius"
+signs[0:20] = "capricorn"
+signs[21:50] = "aquarius"
+signs[51:79] = "pisces"
+
+# task1
+def interpret_western_sign(day, month):
+ year_day = datetime.date(2015, month, day).timetuple().tm_yday
+ if year_day == 356:
+ year_day = 0
+ return sorted(signs[year_day])[0].data
+
+chinese_signs = [
+ "rat",
+ "ox",
+ "tiger",
+ "rabbit",
+ "dragon",
+ "snake",
+ "horse",
+ "sheep",
+ "monkey",
+ "rooster",
+ "dog",
+ "pig"
+]
+
+# task 2
+def interpret_chinese_sign(year):
+ index = (year - 1900) % 12
+ return chinese_signs[index]
+
+# task 3
+def interpret_both_signs(day, month, year):
+ western = interpret_western_sign(day, month)
+ chin = interpret_chinese_sign(year)
+ return (western, chin)