In: Advanced Math
SIGNS =
'ARI:03,21--04,19;TAU:04,20--05,20;GEM:05,21--06,21;CAN:06,22--07,22;'
+ \
'LEO:07,23--08,22;VIR:08,23--09,22;LIB:09,23--10,23;SCO:10,24--11,20;'
+ \
'SAG:11,21--12,21;CAP:12,22--01,20;AQU:01,21--02,21;PIS:02,22--03,20;'
def find_astrological_sign(month: int, date: int) ->
str:
'''
Given two int values representing a month and a date, return
a
3-character string that gives us what star sign a person born in
that
month and on that date belongs to. Use the SIGNS string
(already
defined for you at the top of this file) to figure this out.
NOTE: A lot of string slicing to do here. It looks like
the
information for each sign is exactly 17 characters long.
We can probably use that.
>>> find_astrological_sign(8, 24)
'VIR'
>>> find_astrological_sign(12, 31)
'CAP'
'''
Here is my attempt, I don't know what's wrong
def find_astrological_sign(month, date):
sign_list = SIGNS.split(";")
for s in sign_list:
if s != "":
start_m = int(s[4:6])
start_d = int(s[7:9])
end_m = int(s[11:13])
end_d = int(s[14:16])
if (start_m == month and end_d <= date) or (end_m == month and
end_d >= date):
return s[12:]
Solution:
import time
SIGNS = '03,21-04,19=ARI;04,20-
05,20=TAU;05,21-06,21=GEM;06,22-
07,22=CAN;07,23-08,22=LEO;08,23-
09,22=VIR;09,23-10,23=LIB;10,24-
11,20=SCO;11,21-12,21=SAG;12,22-
01,20=CAP;01,21-02,21=AQU;02,22-03,20=PIS;'
daysMonths = (31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] #storing all the days in every month
signs = ["] * SIGNS.count(';') #as every passage in SIGNS is delimited by a ; character
stars = [[]] * SIGNS.count(';'})
#making a different 'signs rundown and 'stars' list with
all the passages in SIGNS variable and all the months
containing all days separately
i,j=0,- 1
while I < len(stars):
stars[i] = ["] * daysMonths[i]
signs[i] = SIGNS[j + 1: SIGNS.index(';' j + 1)]
j = SIGNS. index(';;, j + 1)
i= i +1
#done
#populating all the times of the month with their repective starsigns
i=0
while I < len(signs):
ml, d1 = int(signs[i][O : 2]), int(signs[i][3 : 5])
m2, d2 = int(signs[i][6 : 8]), int(signs[i][9 : 11))
s = signs[i)[12 : ]
y=d1-1
while y < daysMonths[m1 - 1]:
stars[m1 - 1][y] =s
y=y+l
y=0
while y < d2 : stars [m2 - 1][y] =s
y=y + 1
i=i + 1
#done
#you can enter any month and date and check for the starsigns
def find_astrological_sign(month, date): return stars[month - 1][date - 1]
m, d = [int(x) for x in input(" Enter the date and the month in a solitary line : ").split()]
print(find_astrological_sign(m, d))