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

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

Към профила на Георги Гроздев

Резултати

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

Код

def interpret_western_sign(day, month):
date_list = {1: (21, "capricorn", "aquarius"),
2: (20, "aquarius", "pisces"),
3: (21, "pisces", "aries"),
4: (21, "aries", "taurus"),
5: (21, "taurus", "gemini"),
6: (21, "gemini", "cancer"),
7: (23, "cancer", "leo"),
8: (23, "leo", "virgo"),
9: (23, "virgo", "libra"),
10: (23, "libra", "scorpio"),
11: (22, "scorpio", "sagittarius"),
12: (22, "sagittarius", "capricorn")}
if date_list[month][0] > day:
output = date_list[month][1]
else:
output = date_list[month][2]
return output
def interpret_chinese_sign(year):
chinese_zodiac_signs = ["monkey", "rooster", "dog", "pig",
"rat", "ox", "tiger", "rabbit",
"dragon", "snake", "horse", "sheep"]
output = chinese_zodiac_signs[year % 12]
return output
def interpret_both_signs(day, month, year):
return interpret_western_sign(day, month), interpret_chinese_sign(year)

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

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

OK

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

Георги обнови решението на 08.03.2015 12:31 (преди около 9 години)

+def interpret_western_sign(day, month):
+ date_list = {"1": 21, "2": 20, "3": 21, "4": 21, "5": 21, "6": 21, "7": 23, "8": 23, "9": 23, "10": 23, "11": 22, "12": 22}
+ output = ""
+ if month == 1:
+ if date_list[str(month)] > day:
+ output = "capricorn"
+ else:
+ output = "aquarius"
+ elif month == 2:
+ if date_list[str(month)] > day:
+ output = "aquarius"
+ else:
+ output = "pisces"
+ elif month == 3:
+ if date_list[str(month)] > day:
+ output = "pisces"
+ else:
+ output = "aries"
+ elif month == 4:
+ if date_list[str(month)] > day:
+ output = "aries"
+ else:
+ output = "taurus"
+ elif month == 5:
+ if date_list[str(month)] > day:
+ output = "taurus"
+ else:
+ output = "gemini"
+ elif month == 6:
+ if date_list[str(month)] > day:
+ output = "gemini"
+ else:
+ output = "cancer"
+ elif month == 7:
+ if date_list[str(month)] > day:
+ output = "cancer"
+ else:
+ output = "leo"
+ elif month == 8:
+ if date_list[str(month)] > day:
+ output = "leo"
+ else:
+ output = "virgo"
+ elif month == 9:
+ if date_list[str(month)] > day:
+ output = "virgo"
+ else:
+ output = "libra"
+ elif month == 10:
+ if date_list[str(month)] > day:
+ output = "libra"
+ else:
+ output = "scorpio"
+ elif month == 11:
+ if date_list[str(month)] > day:
+ output = "scorpio"
+ else:
+ output = "sagittarius"
+ elif month == 12:
+ if date_list[str(month)] > day:
+ output = "sagittarius"
+ else:
+ output = "capricorn"
+ return output
+
+def interpret_chinese_sign(year):
+ chinese_zodiac_signs = ["monkey", "rooster", "dog", "pig", "rat", "ox", "tiger", "rabbit", "dragon", "snake", "horse", "sheep"]
+ output = chinese_zodiac_signs[year % 12]
+ return output
+
+
+def interpret_both_signs(day, month, year):
+ return interpret_western_sign(day, month), interpret_chinese_sign(year)
  • имаш редове над 79 символа, а не трябва
  • можеш да ползваш int за ключове в речник и така ще премахнеш това досадно castване към str, което правиш в if-овете
  • впрочем, защо не се пробваш да бъдеш една идея по-хитър и да предадеш решение без 12 броя if-a :)

Георги обнови решението на 08.03.2015 17:25 (преди около 9 години)

def interpret_western_sign(day, month):
- date_list = {"1": 21, "2": 20, "3": 21, "4": 21, "5": 21, "6": 21, "7": 23, "8": 23, "9": 23, "10": 23, "11": 22, "12": 22}
- output = ""
- if month == 1:
- if date_list[str(month)] > day:
- output = "capricorn"
- else:
- output = "aquarius"
- elif month == 2:
- if date_list[str(month)] > day:
- output = "aquarius"
- else:
- output = "pisces"
- elif month == 3:
- if date_list[str(month)] > day:
- output = "pisces"
- else:
- output = "aries"
- elif month == 4:
- if date_list[str(month)] > day:
- output = "aries"
- else:
- output = "taurus"
- elif month == 5:
- if date_list[str(month)] > day:
- output = "taurus"
- else:
- output = "gemini"
- elif month == 6:
- if date_list[str(month)] > day:
- output = "gemini"
- else:
- output = "cancer"
- elif month == 7:
- if date_list[str(month)] > day:
- output = "cancer"
- else:
- output = "leo"
- elif month == 8:
- if date_list[str(month)] > day:
- output = "leo"
- else:
- output = "virgo"
- elif month == 9:
- if date_list[str(month)] > day:
- output = "virgo"
- else:
- output = "libra"
- elif month == 10:
- if date_list[str(month)] > day:
- output = "libra"
- else:
- output = "scorpio"
- elif month == 11:
- if date_list[str(month)] > day:
- output = "scorpio"
- else:
- output = "sagittarius"
- elif month == 12:
- if date_list[str(month)] > day:
- output = "sagittarius"
- else:
- output = "capricorn"
+ date_list = {1: (21, "capricorn", "aquarius"),
+ 2: (20, "aquarius", "pisces"),
+ 3: (21, "pisces", "aries"),
+ 4: (21, "aries", "taurus"),
+ 5: (21, "taurus", "gemini"),
+ 6: (21, "gemini", "cancer"),
+ 7: (23, "cancer", "leo"),
+ 8: (23, "leo", "virgo"),
+ 9: (23, "virgo", "libra"),
+ 10: (23, "libra", "scorpio"),
+ 11: (22, "scorpio", "sagittarius"),
+ 12: (22, "sagittarius", "capricorn")}
+
+ if date_list[month][0] > day:
+ output = date_list[month][1]
+ else:
+ output = date_list[month][2]
+
return output
+
def interpret_chinese_sign(year):
- chinese_zodiac_signs = ["monkey", "rooster", "dog", "pig", "rat", "ox", "tiger", "rabbit", "dragon", "snake", "horse", "sheep"]
+ chinese_zodiac_signs = ["monkey", "rooster", "dog", "pig",
+ "rat", "ox", "tiger", "rabbit",
+ "dragon", "snake", "horse", "sheep"]
output = chinese_zodiac_signs[year % 12]
return output
def interpret_both_signs(day, month, year):
- return interpret_western_sign(day, month), interpret_chinese_sign(year)
+ return interpret_western_sign(day, month), interpret_chinese_sign(year)

Добро решение, забележката ми е, че конвенцията за константи в Питон е името на променливата да е с ГЛАВНИ_БУКВИ и те да са в началото на файла. Много рядко има смисъл константата да е част от дефиницията на функцията ти.