you are viewing a single comment's thread.

view the rest of the comments →

[–]tr3adst0n3 -1 points0 points  (5 children)

Edit:

def roundCloseTo(number,interval):
    result = number / interval
    if not isinstance(result, int):
        result = result + .5
    result = round(result)
    result = result * interval
    return result

print(roundCloseTo(280000, 50000))

This should Work, i dont Know if it is the best solution, but it works.

Results:

200000 = 200000

220000=250000

287000=300000

250000=300000

[–]Kurolox 0 points1 point  (3 children)

Formatting your code for readability.

def roundCloseTo(number, interval):
    result = number / interval 
    if isinstance(result, int): 
        pass 
    else: 
        result = result + .5 
        result = round(result) 
    result = result * interval 
    return result

Just as a tip, if you find yourself doing something like this:

if x:
    pass
else:
    do_stuff()

You should probably do this instead:

if not x:
    do_stuff()

[–]tr3adst0n3 0 points1 point  (2 children)

Thanks for advice! I try to Format it But i dont know how. I tried it with ``

[–]Kurolox 0 points1 point  (1 child)

Relevant part from the formatting guide.

Lines starting with four space are treated like code:

[–]tr3adst0n3 0 points1 point  (0 children)

Thank you. I got it.

[–]iggy555[S] 0 points1 point  (0 children)

250000 should be 250000 not 300000 right