python - What function has these integer results? -
for example, have reference number a = 15 , b= 3.
- if
x=2,f(a,b,x) = 1because if 1 divide 15 3 parts, number 2 in first part. - if
x=7,f(a,b,x) = 2because if 1 divide 15 3 parts, number 7 in second part. - if
x=15,f(a,b,x) = 3because if 1 divide 15 3 parts, number 15 in third part. - if x<0 or >15 results irrelevant me.
is there built-in function this?
i can't think of single built-in function that. not difficult write one:
def f(a, b, x): return (x - 1) * b // + 1 in range(1, 16): print i, f(15, 3, i) this prints out
1 1 2 1 3 1 4 1 5 1 6 2 7 2 8 2 9 2 10 2 11 3 12 3 13 3 14 3 15 3 (it not entirely clear question how, , if, x=0 needs handled; answer considers outside valid range.)
Comments
Post a Comment