Question

In: Computer Science

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;' def find_astrological_sign(month, date

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;' def find_astrological_sign(month, date): ''' (int, 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. The information for each sign is exactly 16 characters long. >>> find_astrological_sign(8, 24) 'VIR' >>> find_astrological_sign(1, 15) 'CAP' How can this be done using lists?

Solutions

Expert Solution

Answer:

Code:

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;'

def find_astrological_sign(month, date):

signs_list = SIGNS.split(";")

for sign in signs_list:

if sign!="":

m1 = int(sign[0:2])

d1 = int(sign[3:5])

m2 = int(sign[6:8])

d2 = int(sign[9:11])

if(m1==month and d1<=date) or (m2==month and d2>=date):

return sign[12:]

print(find_astrological_sign(8, 24))

print(find_astrological_sign(1, 15))


Related Solutions

SIGN_GROUPS = '[ARI,LEO,SAG]-[TAU,VIR,CAP]-[GEM,LIB,AQU]-[PIS,SCO,CAN]' def get_sign_group(sign): ''' (str) -> int Given a three character string representing a...
SIGN_GROUPS = '[ARI,LEO,SAG]-[TAU,VIR,CAP]-[GEM,LIB,AQU]-[PIS,SCO,CAN]' def get_sign_group(sign): ''' (str) -> int Given a three character string representing a star sign, return which group (out of 0, 1, 2, or 3) this star sign belongs to. Use the SIGN_GROUPS string (already defined for you above) to figure out the group. i.e. As given by this string '[ARI,LEO,SAG]-[TAU,VIR,CAP]-[GEM,LIB,AQU]-[PIS,SCO,CAN]' the signs ARI, LEO and SAG are in group 0, the signs TAU, VIR, CAP are in group 1, and so on. >>> get_sign_group('ARI') 0 >>>...
One can find out date of the month when someone was born by asking five questions....
One can find out date of the month when someone was born by asking five questions. Each question asks whether the day is in one of the five sets of numbers below 1 3 5 7          2 3   6   7             4 5   6 7             8 9 10 11           16 17 18 19 9 11 13 15                  10 11 14 15          12 13 14 15          12 13 14 15          20 21 22 23 17 19 21 23                18...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT