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

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

Към профила на Павел Павлов

Резултати

  • 8 точки от тестове
  • 1 отнета точка
  • 7 точки общо
  • 5 успешни тест(а)
  • 1 неуспешни тест(а)

Код

def interpret_western_sign(day, month):
sign_one = {3: ['pisces', 'aries'], 4: ['aries', 'taurus'],
5: ['taurus', 'gemini'], 6: ['gemini', 'cancer'],
1: ['capricorn', 'aquarius']}
sign_two = {7: ['cancer', 'leo'], 8: ['leo', 'virgo'],
9: ['virgo', 'libra'], 10: ['libra', 'scorpio']}
sign_three = {11: ['scorpio', 'sagittarius'],
12: ['sagittarius', 'capricorn']}
sign_four = {2: ['aquarius', 'pisces']}
if month in sign_one and day < 21:
return (sign_one.get(month))[0]
elif month in sign_one:
return (sign_one.get(month))[1]
if month in sign_two and day < 23:
return (sign_two.get(month))[0]
elif month in sign_two:
return (sign_two.get(month))[1]
if month in sign_three and day < 22:
return (sign_three.get(month))[0]
elif month in sign_three:
return (sign_three.get(month))[1]
if month in sign_four and day < 19:
return (sign_four.get(month))[0]
elif month in sign_four:
return (sign_four.get(month))[1]
def interpret_chinese_sign(year):
for i in range(0, 2200, 12):
if year == i:
return 'monkey'
for i in range(1, 2201, 12):
if year == i:
return 'rooster'
for i in range(2, 2202, 12):
if year == i:
return 'dog'
for i in range(3, 2203, 12):
if year == i:
return 'pig'
for i in range(4, 2204, 12):
if year == i:
return 'rat'
for i in range(5, 2205, 12):
if year == i:
return 'ox'
for i in range(6, 2206, 12):
if year == i:
return 'tiger'
for i in range(7, 2207, 12):
if year == i:
return 'rabbit'
for i in range(8, 2208, 12):
if year == i:
return 'dragon'
for i in range(9, 2209, 12):
if year == i:
return 'snake'
for i in range(10, 2210, 12):
if year == i:
return 'horse'
for i in range(11, 2211, 12):
if year == i:
return 'sheep'
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month), interpret_chinese_sign(year))

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

...F..
======================================================================
FAIL: test_negative_years (test.TestSigns)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150312-24164-1v89qgb/test.py", line 26, in test_negative_years
    self.assertEqual(solution.interpret_chinese_sign(-23), 'rooster')
AssertionError: None != 'rooster'

----------------------------------------------------------------------
Ran 6 tests in 0.009s

FAILED (failures=1)

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

Павел обнови решението на 11.03.2015 16:26 (преди над 9 години)

+def interpret_western_sign(day, month):
+ sign_one = {3: ['pisces', 'aries'], 4: ['aries', 'taurus'],
+ 5: ['taurus', 'gemini'], 6: ['gemini', 'cancer'],
+ 1: ['capricorn', 'aquarius']}
+
+ sign_two = {7: ['cancer', 'leo'], 8: ['leo', 'virgo'],
+ 9: ['virgo', 'libra'], 10: ['libra', 'scorpio']}
+
+ sign_three = {11: ['scorpio', 'sagittarius'],
+ 12: ['sagittarius', 'capricorn']}
+
+ sign_four = {2: ['aquarius', 'pisces']}
+
+ if month in sign_one and day < 21:
+ return (sign_one.get(month))[0]
+ elif month in sign_one:
+ return (sign_one.get(month))[1]
+ if month in sign_two and day < 23:
+ return (sign_two.get(month))[0]
+ elif month in sign_two:
+ return (sign_two.get(month))[1]
+ if month in sign_three and day < 22:
+ return (sign_three.get(month))[0]
+ elif month in sign_three:
+ return (sign_three.get(month))[1]
+ if month in sign_four and day < 19:
+ return (sign_four.get(month))[0]
+ elif month in sign_four:
+ return (sign_four.get(month))[1]
+
+
+def interpret_chinese_sign(year):
+ for i in range(0, 2200, 12):
+ if year == i:
+ return 'monkey'
+
+ for i in range(1, 2201, 12):
+ if year == i:
+ return 'rooster'
+
+ for i in range(2, 2202, 12):
+ if year == i:
+ return 'dog'
+
+ for i in range(3, 2203, 12):
+ if year == i:
+ return 'pig'
+
+ for i in range(4, 2204, 12):
+ if year == i:
+ return 'rat'
+
+ for i in range(5, 2205, 12):
+ if year == i:
+ return 'ox'
+
+ for i in range(6, 2206, 12):
+ if year == i:
+ return 'tiger'
+
+ for i in range(7, 2207, 12):
+ if year == i:
+ return 'rabbit'
+
+ for i in range(8, 2208, 12):
+ if year == i:
+ return 'dragon'
+
+ for i in range(9, 2209, 12):
+ if year == i:
+ return 'snake'
+
+ for i in range(10, 2210, 12):
+ if year == i:
+ return 'horse'
+
+ for i in range(11, 2211, 12):
+ if year == i:
+ return 'sheep'
+
+
+def interpret_both_signs(day, month, year):
+ return (interpret_western_sign(day, month), interpret_chinese_sign(year))
  • Твърде много if-ове
  • Защо имаш три речника в първата функция?
  • Наистина ли ти е необходим методът get след като знаеш, че входните данни ще са валидни?
  • Втората функция има прекалено много обхождания и въпреки всички проверки изпуска много случаи. Тук for-овете са повече от необходимото.