PYTHON 算法题:Categorize New Member

The Western Suburbs Croquet Club has two categories of membership, Senior and Open. They would like your help with an application form that will tell prospective members which category they will be placed.

To be a senior, a member must be at least 55 years old and have a handicap greater than 7. In this croquet club, handicaps range from -2 to +26; the better the player the lower the handicap.

test.assert_equals(openOrSenior([[45, 12],[55,21],[19, -2],[104, 20]]),['Open', 'Senior', 'Open', 'Senior'])
test.assert_equals(openOrSenior([[16, 23],[73,1],[56, 20],[1, -1]]),['Open', 'Open', 'Senior', 'Open'])

这个题思路比较简单:

def openOrSenior(data):
    l=[]
    for i in data:
        if i[0]>=55 and i[1]>7:
            l.append('senior')
        else:
            l.append('open')
    return l






猜你喜欢

转载自blog.csdn.net/qulengdai0563/article/details/80112563