Question

SIGN_GROUPS = '[ARI,LEO,SAG]-[TAU,VIR,CAP]-[GEM,LIB,AQU]-[PIS,SCO,CAN] def find_astrological_compatibility(sign_1, sign_2): ''' (str, str) -> int Given two 3-character strings representing...

SIGN_GROUPS = '[ARI,LEO,SAG]-[TAU,VIR,CAP]-[GEM,LIB,AQU]-[PIS,SCO,CAN]
def find_astrological_compatibility(sign_1, sign_2):
    '''
    (str, str) -> int

    Given two 3-character strings representing star signs, return an int
    representing how compatible they are.
    
    According to Bob's rules, the compatibility between signs is calculated
    based on the SIGN_GROUPS they belong in, as follows:
    - If the signs are in the same group, return 100
    - If both the signs are in an odd-numbered group (i.e. 1 and 3)
      OR if both are in an even group (i.e. 0 and 2), then return 70
    - For all other cases, return 50

    >>> find_astrological_compatibility('ARI', 'LEO')
    100

    >>> find_astrological_compatibility('GEM', 'LIB')
    100

    >>> find_astrological_compatibility('SAG', 'AQU')
    70
    
    >>> find_astrological_compatibility('VIR', 'PIS')
    70
    
    >>> find_astrological_compatibility('LEO', 'TAU')
    50

    >>> find_astrological_compatibility('AQU', 'SCO')
    50
    '''
0 0
Add a comment Improve this question Transcribed image text
Answer #1
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

    >>> get_sign_group('CAN')
    3
    """
    lst = [['ARI', 'LEO', 'SAG'], ['TAU', 'VIR', 'CAP'], ['GEM', 'LIB', 'AQU'], ['PIS', 'SCO', 'CAN']]
    for i in range(len(lst)):
        if sign in lst[i]:
            return i
    return -1


def find_astrological_compatibility(sign_1, sign_2):
    """
    (str, str) -> int

    Given two 3-character strings representing star signs, return an int
    representing how compatible they are.

    According to Bob's rules, the compatibility between signs is calculated
    based on the SIGN_GROUPS they belong in, as follows:
    - If the signs are in the same group, return 100
    - If both the signs are in an odd-numbered group (i.e. 1 and 3)
      OR if both are in an even group (i.e. 0 and 2), then return 70
    - For all other cases, return 50

    >>> find_astrological_compatibility('ARI', 'LEO')
    100

    >>> find_astrological_compatibility('GEM', 'LIB')
    100

    >>> find_astrological_compatibility('SAG', 'AQU')
    70

    >>> find_astrological_compatibility('VIR', 'PIS')
    70

    >>> find_astrological_compatibility('LEO', 'TAU')
    50

    >>> find_astrological_compatibility('AQU', 'SCO')
    50
    """
    s1 = get_sign_group(sign_1)
    s2 = get_sign_group(sign_2)
    if s1 == s2:
        return 100
    elif s1 % 2 == 1 and s2 % 2 == 1:
        return 70
    elif s1 % 2 == 0 and s2 % 2 == 0:
        return 70
    else:
        return 50


Add a comment
Know the answer?
Add Answer to:
SIGN_GROUPS = '[ARI,LEO,SAG]-[TAU,VIR,CAP]-[GEM,LIB,AQU]-[PIS,SCO,CAN] def find_astrological_compatibility(sign_1, sign_2): ''' (str, str) -> int Given two 3-character strings representing...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT