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

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

Към профила на Цветелина Александрова

Резултати

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

Код

"""
zodiac signs fun task
"""
def interpret_western_sign(day, month):
"""
return string for western sign
"""
zodiacs = ['aries', 'taurus', 'gemini',
'cancer', 'leo', 'virgo',
'libra', 'scorpio', 'sagittarius',
'capricorn', 'aquarius', 'pisces'
]
if month < 1 or month > 12:
return 'Invalid month argument value'
if day < 1 or day > 31:
return 'Invalid day argument value'
for i in range(1, 13):
turn_day = 20
zodiac_index = i - 4
if month == i:
if month < 4:
zodiac_index = i + 8
if month == 2:
turn_day = 18
if month > 6:
turn_day = 22
if month > 10:
turn_day = 21
if day <= turn_day:
return zodiacs[zodiac_index]
else:
if zodiac_index == 11:
return zodiacs[0]
else:
return zodiacs[zodiac_index + 1]
def interpret_chinese_sign(year):
"""
return string for chinese sign
"""
zodiacs = ['monkey', 'rooster', 'dog',
'pig', 'rat', 'ox', 'tiger',
'rabbit', 'dragon', 'snake',
'horse', 'sheep',
]
for i in range(0, 12):
if year % 12 == i:
return zodiacs[i]
def interpret_both_signs(day, month, year):
"""
return tuple of 2 strings for both signs
"""
western = interpret_western_sign(day, month)
chinese = interpret_chinese_sign(year)
return (western, chinese)

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

......
----------------------------------------------------------------------
Ran 6 tests in 0.008s

OK

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

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

+#return string for western sign
+def interpret_western_sign(day, month):
+ zodiacs = ['aries', 'taurus', 'gemini',
+ 'cancer', 'leo', 'virgo',
+ 'libra', 'scorpio', 'sagittarius',
+ 'capricorn', 'aquarius', 'pisces'
+ ]
+ if month < 1 or month > 12:
+ return 'Invalid month argument value'
+ if day < 1 or day > 31:
+ return 'Invalid day argument value'
+ for i in range(1, 13):
+ turn_day = 20
+ decrem = i - 4
+ if month == i:
+ if month < 4:
+ decrem = i + 8
+ if month == 2:
+ turn_day = 18
+ if month > 6:
+ turn_day = 22
+ if month > 10:
+ turn_day = 21
+ if day <= turn_day:
+ return zodiacs[decrem]
+ else:
+ if decrem == 11:
+ return zodiacs[0]
+ else:
+ return zodiacs[decrem + 1]
+#return string for chinese sign
+def interpret_chinese_sign(year):
+ zodiacs = ['monkey', 'rooster', 'dog',
+ 'pig', 'rat', 'ox', 'tiger',
+ 'rabbit', 'dragon', 'snake',
+ 'horse', 'sheep',
+ ]
+ for i in range(0, 12):
+ if year % 12 == i:
+ return zodiacs[i]
+#return tuple of 2 strings for both signs
+def interpret_both_signs(day, month, year):
+ western = interpret_western_sign(day, month)
+ chinese = interpret_chinese_sign(year)
+ return (western, chinese)

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

-#return string for western sign
+"""
+zodiac signs fun task
+"""
def interpret_western_sign(day, month):
+ """
+ return string for western sign
+ """
zodiacs = ['aries', 'taurus', 'gemini',
'cancer', 'leo', 'virgo',
'libra', 'scorpio', 'sagittarius',
'capricorn', 'aquarius', 'pisces'
]
if month < 1 or month > 12:
return 'Invalid month argument value'
if day < 1 or day > 31:
return 'Invalid day argument value'
for i in range(1, 13):
turn_day = 20
decrem = i - 4
if month == i:
if month < 4:
decrem = i + 8
if month == 2:
turn_day = 18
if month > 6:
turn_day = 22
if month > 10:
turn_day = 21
if day <= turn_day:
return zodiacs[decrem]
else:
if decrem == 11:
return zodiacs[0]
else:
return zodiacs[decrem + 1]
-#return string for chinese sign
def interpret_chinese_sign(year):
+ """
+ return string for chinese sign
+ """
zodiacs = ['monkey', 'rooster', 'dog',
'pig', 'rat', 'ox', 'tiger',
'rabbit', 'dragon', 'snake',
- 'horse', 'sheep',
+ 'horse', 'sheep',
]
for i in range(0, 12):
if year % 12 == i:
return zodiacs[i]
-#return tuple of 2 strings for both signs
def interpret_both_signs(day, month, year):
+ """
+ return tuple of 2 strings for both signs
+ """
western = interpret_western_sign(day, month)
chinese = interpret_chinese_sign(year)
- return (western, chinese)
+ return (western, chinese)
+

Погледни PEP8. Трябва да оставяш по 2 празни реда между функциите. Името decrem не е особено описателно. Ако не можеш да измислиш добро име, най-вероятно тази променлива не ти трябва и има по-лесен начин без нея.

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

"""
zodiac signs fun task
"""
def interpret_western_sign(day, month):
"""
return string for western sign
"""
zodiacs = ['aries', 'taurus', 'gemini',
'cancer', 'leo', 'virgo',
'libra', 'scorpio', 'sagittarius',
'capricorn', 'aquarius', 'pisces'
]
if month < 1 or month > 12:
return 'Invalid month argument value'
if day < 1 or day > 31:
return 'Invalid day argument value'
for i in range(1, 13):
turn_day = 20
- decrem = i - 4
+ zodiac_index = i - 4
if month == i:
if month < 4:
- decrem = i + 8
+ zodiac_index = i + 8
if month == 2:
turn_day = 18
if month > 6:
turn_day = 22
if month > 10:
turn_day = 21
if day <= turn_day:
- return zodiacs[decrem]
+ return zodiacs[zodiac_index]
else:
- if decrem == 11:
+ if zodiac_index == 11:
return zodiacs[0]
else:
- return zodiacs[decrem + 1]
+ return zodiacs[zodiac_index + 1]
+
+
def interpret_chinese_sign(year):
"""
return string for chinese sign
"""
zodiacs = ['monkey', 'rooster', 'dog',
'pig', 'rat', 'ox', 'tiger',
'rabbit', 'dragon', 'snake',
'horse', 'sheep',
]
for i in range(0, 12):
if year % 12 == i:
return zodiacs[i]
+
+
def interpret_both_signs(day, month, year):
"""
return tuple of 2 strings for both signs
"""
western = interpret_western_sign(day, month)
chinese = interpret_chinese_sign(year)
return (western, chinese)