Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Define score as follows:

def score(x, ncand=10):
    s = piecewise([([i,i], ncand - i) for i in range(ncand)])
    return s(x)

Then you can use score as in the following examples:

sage: score(7)
3
sage: score(3, ncand=7)
4
sage: score(3,7)
4

Observe that, if omitted, the value of ncand is 10.