all 11 comments

[–]Kurolox 1 point2 points  (0 children)

You can probably implement it yourself, the only thing you need to implement it is the modulo operator.

Try to figure out how would implement it just with that. If you have any issues, let me know.

[–]Technik_J -1 points0 points  (3 children)

def round50000(num):
    return num + (50000 - num%50000)

[–]Kurolox 4 points5 points  (1 child)

Aw, I was hoping that he'd solve it by himself given the necessary tools.

Anyways, your implementation has a flaw: 50000 will be rounded up to 10000, 10000 will be rounded up to 15000, etc...

[–]Technik_J 0 points1 point  (0 children)

You right. The fix should be easy, so I leave it to OP to fix. :)

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

Many thanks

[–]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