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

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

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

Резултати

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

Код

def interpret_western_sign(day, month):
zodiac = {
"aquarius": [[1, range(21, 32)], [2, range(1, 19)]],
"pisces": [[2, range(19, 20)], [3, range(1, 21)]],
"aries": [[3, range(21, 32)], [4, range(1, 21)]],
"taurus": [[4, range(21, 31)], [5, range(1, 21)]],
"gemini": [[5, range(21, 33)], [6, range(1, 21)]],
"cancer": [[6, range(21, 31)], [7, range(1, 23)]],
"leo": [[7, range(23, 32)], [8, range(1, 23)]],
"virgo": [[8, range(23, 32)], [9, range(1, 23)]],
"libra": [[9, range(23, 31)], [10, range(1, 23)]],
"scorpio": [[10, range(23, 32)], [11, range(1, 22)]],
"sagittarius": [[11, range(22, 31)], [12, range(1, 22)]],
"capricorn": [[12, range(22, 32)], [1, range(1, 21)]]
}
for sign in zodiac:
for date in zodiac[sign]:
if month == date[0] and day in date[1]:
return sign
def interpret_chinese_sign(year):
chinese_zodiac = {
"monkey": 0,
"rooster": 1,
"dog": 2,
"pig": 3,
"rat": 4,
"ox": 5,
"tiger": 6,
"rabbit": 7,
"dragon": 8,
"snake": 9,
"horse": 10,
"sheep": 11
}
for sign in chinese_zodiac:
if year % 12 == chinese_zodiac[sign]:
return sign
def interpret_both_signs(day, month, year):
western_sign = interpret_western_sign(day, month)
chinese_sign = interpret_chinese_sign(year)
both_signs = (western_sign, chinese_sign)
return both_signs

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

..F...
======================================================================
FAIL: test_leap_year (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-1a9jta1/test.py", line 32, in test_leap_year
    self.assertEqual(solution.interpret_western_sign(29, 2), 'pisces')
AssertionError: None != 'pisces'

----------------------------------------------------------------------
Ran 6 tests in 0.010s

FAILED (failures=1)

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

Станислав обнови решението на 08.03.2015 12:25 (преди над 9 години)

+def interpret_chinese_sign(year):
+ birth_year = year % 12
+ if birth_year == 0:
+ return("monkey")
+ elif birth_year == 1:
+ return("rooster")
+ elif birth_year == 2:
+ return("dog")
+ elif birth_year == 3:
+ return("pig")
+ elif birth_year == 4:
+ return("rat")
+ elif birth_year == 5:
+ return("ox")
+ elif birth_year == 6:
+ return("tiger")
+ elif birth_year == 7:
+ return("rabbit")
+ elif birth_year == 8:
+ return("dragon")
+ elif birth_year == 9:
+ return("snake")
+ elif birth_year == 10:
+ return("horse")
+ else:
+ return("sheep")
+
+
+def interpret_western_sign(day, month):
+ if month == 1:
+ if day > 20:
+ return("aquarius")
+ else:
+ return("capricorn")
+ elif month == 2:
+ if day > 18:
+ return("pisces")
+ else:
+ return("aquarius")
+ elif month == 3:
+ if day > 20:
+ return("aries")
+ else:
+ return("pisces")
+ elif month == 4:
+ if day > 20:
+ return("taurus")
+ else:
+ return("aries")
+ elif month == 5:
+ if day > 20:
+ return("gemini")
+ else:
+ return("taurus")
+ elif month == 6:
+ if day > 20:
+ return("cancer")
+ else:
+ return("gemini")
+ elif month == 7:
+ if day > 22:
+ return("leo")
+ else:
+ return("cancer")
+ elif month == 8:
+ if day > 22:
+ return("virgo")
+ else:
+ return("leo")
+ elif month == 9:
+ if day > 22:
+ return("libra")
+ else:
+ return("virgio")
+ elif month == 10:
+ if day > 22:
+ return("scorpio")
+ else:
+ return("libra")
+ elif month == 11:
+ if day > 21:
+ return("sagittarius")
+ else:
+ return("scorpio")
+ elif month == 12:
+ if day > 21:
+ return("capricorn")
+ else:
+ return("sagittarius")
+
+
+def interpret_both_signs(day, month, year):
+ western_sign = interpret_western_sign(day, month)
+ chinese_sign = interpret_chinese_sign(year)
+ both_signs = (western_sign, chinese_sign)
+
+ return both_signs

Станислав обнови решението на 08.03.2015 14:56 (преди над 9 години)

def interpret_chinese_sign(year):
birth_year = year % 12
if birth_year == 0:
return("monkey")
elif birth_year == 1:
return("rooster")
elif birth_year == 2:
return("dog")
elif birth_year == 3:
return("pig")
elif birth_year == 4:
return("rat")
elif birth_year == 5:
return("ox")
elif birth_year == 6:
return("tiger")
elif birth_year == 7:
return("rabbit")
elif birth_year == 8:
return("dragon")
elif birth_year == 9:
return("snake")
elif birth_year == 10:
return("horse")
else:
return("sheep")
def interpret_western_sign(day, month):
- if month == 1:
- if day > 20:
- return("aquarius")
- else:
- return("capricorn")
- elif month == 2:
- if day > 18:
- return("pisces")
- else:
- return("aquarius")
- elif month == 3:
- if day > 20:
- return("aries")
- else:
- return("pisces")
- elif month == 4:
- if day > 20:
- return("taurus")
- else:
- return("aries")
- elif month == 5:
- if day > 20:
- return("gemini")
- else:
- return("taurus")
- elif month == 6:
- if day > 20:
- return("cancer")
- else:
- return("gemini")
- elif month == 7:
- if day > 22:
- return("leo")
- else:
- return("cancer")
- elif month == 8:
- if day > 22:
- return("virgo")
- else:
- return("leo")
- elif month == 9:
- if day > 22:
- return("libra")
- else:
- return("virgio")
- elif month == 10:
- if day > 22:
- return("scorpio")
- else:
- return("libra")
- elif month == 11:
- if day > 21:
- return("sagittarius")
- else:
- return("scorpio")
- elif month == 12:
- if day > 21:
- return("capricorn")
- else:
- return("sagittarius")
-
+ if (month == 1 and day > 20) or (month == 2 and day < 19):
+ return("aquarius")
+ elif (month == 2 and day > 18) or (month == 3 and day < 21):
+ return("pisces")
+ elif (month == 3 and day > 20) or (month == 4 and day < 21):
+ return("aries")
+ elif (month == 4 and day > 20) or (month == 5 and day < 21):
+ return("taurus")
+ elif (month == 5 and day > 20) or (month == 6 and day < 21):
+ return("gemini")
+ elif (month == 6 and day > 20) or (month == 7 and day < 23):
+ return("cancer")
+ elif (month == 7 and day > 22) or (month == 8 and day < 23):
+ return("leo")
+ elif (month == 8 and day > 22) or (month == 9 and day < 23):
+ return("virgo")
+ elif (month == 9 and day > 22) or (month == 10 and day < 23):
+ return("libra")
+ elif (month == 10 and day > 22) or (month == 11 and day < 22):
+ return("scorpio")
+ elif (month == 11 and day > 21) or (month == 12 and day < 22):
+ return("sagittarius")
+ else:
+ return("capricorn")
def interpret_both_signs(day, month, year):
western_sign = interpret_western_sign(day, month)
chinese_sign = interpret_chinese_sign(year)
both_signs = (western_sign, chinese_sign)
return both_signs

Станислав обнови решението на 09.03.2015 00:11 (преди над 9 години)

def interpret_chinese_sign(year):
birth_year = year % 12
if birth_year == 0:
return("monkey")
elif birth_year == 1:
return("rooster")
elif birth_year == 2:
return("dog")
elif birth_year == 3:
return("pig")
elif birth_year == 4:
return("rat")
elif birth_year == 5:
return("ox")
elif birth_year == 6:
return("tiger")
elif birth_year == 7:
return("rabbit")
elif birth_year == 8:
return("dragon")
elif birth_year == 9:
return("snake")
elif birth_year == 10:
return("horse")
else:
return("sheep")
-
def interpret_western_sign(day, month):
- if (month == 1 and day > 20) or (month == 2 and day < 19):
- return("aquarius")
- elif (month == 2 and day > 18) or (month == 3 and day < 21):
- return("pisces")
- elif (month == 3 and day > 20) or (month == 4 and day < 21):
- return("aries")
- elif (month == 4 and day > 20) or (month == 5 and day < 21):
- return("taurus")
- elif (month == 5 and day > 20) or (month == 6 and day < 21):
- return("gemini")
- elif (month == 6 and day > 20) or (month == 7 and day < 23):
- return("cancer")
- elif (month == 7 and day > 22) or (month == 8 and day < 23):
- return("leo")
- elif (month == 8 and day > 22) or (month == 9 and day < 23):
- return("virgo")
- elif (month == 9 and day > 22) or (month == 10 and day < 23):
- return("libra")
- elif (month == 10 and day > 22) or (month == 11 and day < 22):
- return("scorpio")
- elif (month == 11 and day > 21) or (month == 12 and day < 22):
- return("sagittarius")
- else:
- return("capricorn")
+
+ # for x in range(20,32):
+ # print(x)
+ dict1 = {
+
+ "aquarius" : [[1, range(21,32)], [2,range(1,19)]],
+ "pisces" : [[2, range(19,20)], [3,range(1,21)]],
+ "aries" : [[3, range(21,32)], [4,range(1,21)]],
+ "taurus" : [[4, range(21,31)], [5,range(1,21)]],
+ "gemini" : [[5, range(21,33)], [6,range(1,21)]],
+ "cancer" : [[6, range(21,31)], [7,range(1,23)]],
+ "leo" : [[7, range(23,32)], [8,range(1,23)]],
+ "virgo" : [[8, range(23,32)], [9,range(1,23)]],
+ "libra" : [[9, range(23,31)], [10,range(1,23)]],
+ "scorpio" : [[10, range(23,32)], [11,range(1,22)]],
+ "sagittarius" : [[11, range(22,31)], [12,range(1,22)]],
+ "capricorn" : [[12, range(22,32)], [1,range(1,21)]],
+
+ }
+
+ for x in dict1:
+ for y in dict1[x]:
+ if month == y[0] and day in y[1]:
+ return x
def interpret_both_signs(day, month, year):
western_sign = interpret_western_sign(day, month)
chinese_sign = interpret_chinese_sign(year)
both_signs = (western_sign, chinese_sign)
return both_signs

Станислав обнови решението на 09.03.2015 00:19 (преди над 9 години)

def interpret_chinese_sign(year):
birth_year = year % 12
if birth_year == 0:
return("monkey")
elif birth_year == 1:
return("rooster")
elif birth_year == 2:
return("dog")
elif birth_year == 3:
return("pig")
elif birth_year == 4:
return("rat")
elif birth_year == 5:
return("ox")
elif birth_year == 6:
return("tiger")
elif birth_year == 7:
return("rabbit")
elif birth_year == 8:
return("dragon")
elif birth_year == 9:
return("snake")
elif birth_year == 10:
return("horse")
else:
return("sheep")
-
def interpret_western_sign(day, month):
- # for x in range(20,32):
- # print(x)
- dict1 = {
+
+ zodiac = {
"aquarius" : [[1, range(21,32)], [2,range(1,19)]],
"pisces" : [[2, range(19,20)], [3,range(1,21)]],
"aries" : [[3, range(21,32)], [4,range(1,21)]],
"taurus" : [[4, range(21,31)], [5,range(1,21)]],
"gemini" : [[5, range(21,33)], [6,range(1,21)]],
"cancer" : [[6, range(21,31)], [7,range(1,23)]],
"leo" : [[7, range(23,32)], [8,range(1,23)]],
"virgo" : [[8, range(23,32)], [9,range(1,23)]],
"libra" : [[9, range(23,31)], [10,range(1,23)]],
"scorpio" : [[10, range(23,32)], [11,range(1,22)]],
"sagittarius" : [[11, range(22,31)], [12,range(1,22)]],
"capricorn" : [[12, range(22,32)], [1,range(1,21)]],
}
- for x in dict1:
- for y in dict1[x]:
- if month == y[0] and day in y[1]:
- return x
+ for sign in zodiac:
+ for date in zodiac[sign]:
+ if month == date[0] and day in date[1]:
+ return sign
def interpret_both_signs(day, month, year):
western_sign = interpret_western_sign(day, month)
chinese_sign = interpret_chinese_sign(year)
both_signs = (western_sign, chinese_sign)
return both_signs

Както се казва в оная реклама "по-добре" :)

Аре сега да го доошлайфваш. Сигурен съм, че може да се сетиш как да махнеш if-овете и от функциията за китайския зодиак.

Откъм стилистична гледна точка:

  • 4 спейса идентация (защо имаш 8 на ред 50)
  • отделяй глобално дефинираните функции с 2 празни реда
  • оставяй интервал само след : в речниците (в момента оставяш и пред знака)
  • махни един от празните редове 28ми или 29ти

За горните 4, отдели примерно един час и си нагласи едитора. Определено ще ти трябва. Подобни забележки ще правим само на първото домашно, след това ще си мълчим кротко и ще взимаме точки жестоко.

Станислав обнови решението на 09.03.2015 15:21 (преди над 9 години)

-def interpret_chinese_sign(year):
- birth_year = year % 12
- if birth_year == 0:
- return("monkey")
- elif birth_year == 1:
- return("rooster")
- elif birth_year == 2:
- return("dog")
- elif birth_year == 3:
- return("pig")
- elif birth_year == 4:
- return("rat")
- elif birth_year == 5:
- return("ox")
- elif birth_year == 6:
- return("tiger")
- elif birth_year == 7:
- return("rabbit")
- elif birth_year == 8:
- return("dragon")
- elif birth_year == 9:
- return("snake")
- elif birth_year == 10:
- return("horse")
- else:
- return("sheep")
def interpret_western_sign(day, month):
-
zodiac = {
- "aquarius" : [[1, range(21,32)], [2,range(1,19)]],
- "pisces" : [[2, range(19,20)], [3,range(1,21)]],
- "aries" : [[3, range(21,32)], [4,range(1,21)]],
- "taurus" : [[4, range(21,31)], [5,range(1,21)]],
- "gemini" : [[5, range(21,33)], [6,range(1,21)]],
- "cancer" : [[6, range(21,31)], [7,range(1,23)]],
- "leo" : [[7, range(23,32)], [8,range(1,23)]],
- "virgo" : [[8, range(23,32)], [9,range(1,23)]],
- "libra" : [[9, range(23,31)], [10,range(1,23)]],
- "scorpio" : [[10, range(23,32)], [11,range(1,22)]],
- "sagittarius" : [[11, range(22,31)], [12,range(1,22)]],
- "capricorn" : [[12, range(22,32)], [1,range(1,21)]],
+ "aquarius": [[1, range(21, 32)], [2, range(1, 19)]],
+ "pisces": [[2, range(19, 20)], [3, range(1, 21)]],
+ "aries": [[3, range(21, 32)], [4, range(1, 21)]],
+ "taurus": [[4, range(21, 31)], [5, range(1, 21)]],
+ "gemini": [[5, range(21, 33)], [6, range(1, 21)]],
+ "cancer": [[6, range(21, 31)], [7, range(1, 23)]],
+ "leo": [[7, range(23, 32)], [8, range(1, 23)]],
+ "virgo": [[8, range(23, 32)], [9, range(1, 23)]],
+ "libra": [[9, range(23, 31)], [10, range(1, 23)]],
+ "scorpio": [[10, range(23, 32)], [11, range(1, 22)]],
+ "sagittarius": [[11, range(22, 31)], [12, range(1, 22)]],
+ "capricorn": [[12, range(22, 32)], [1, range(1, 21)]]
}
for sign in zodiac:
- for date in zodiac[sign]:
+ for date in zodiac[sign]:
if month == date[0] and day in date[1]:
- return sign
+ return sign
+
+def interpret_chinese_sign(year):
+
+ chinese_zodiac = {
+
+ "monkey": 0,
+ "rooster": 1,
+ "dog": 2,
+ "pig": 3,
+ "rat": 4,
+ "ox": 5,
+ "tiger": 6,
+ "rabbit": 7,
+ "dragon": 8,
+ "snake": 9,
+ "horse": 10,
+ "sheep": 11
+
+ }
+
+ for sign in chinese_zodiac:
+ if year % 12 == chinese_zodiac[sign]:
+ return sign
+
+
def interpret_both_signs(day, month, year):
+
western_sign = interpret_western_sign(day, month)
chinese_sign = interpret_chinese_sign(year)
both_signs = (western_sign, chinese_sign)
-
return both_signs