Rounding to the nearest 5

Benjamin J. Racine bjracine at glosten.com
Fri Jan 30 19:19:32 CET 2009


Doesn't this work?

round_by_5.py

>>>>>>>>>>>>>>>>>>>>>>>

import sys

def round_by_5(x= sys.argv[0]):
    x = x/5.
    x = round(x)
    x = x*5
    print(x)
    return x 

Ben R.


-----Original Message-----
From: python-list-bounces+bjracine=glosten.com at python.org [mailto:python-list-bounces+bjracine=glosten.com at python.org] On Behalf Of D'Arcy J.M. Cain
Sent: Friday, January 30, 2009 6:07 AM
To: Steven D'Aprano
Cc: python-list at python.org
Subject: Re: Rounding to the nearest 5

On 30 Jan 2009 06:23:17 GMT
Steven D'Aprano <steven at REMOVE.THIS.cybersource.com.au> wrote:
> On Fri, 30 Jan 2009 00:24:47 -0500, D'Arcy J.M. Cain wrote:
> > That appears to be rounding to nearest 10, not 5.  Clarify your 
> > requirements first.
> 
> Look again. 36 => 35.

You are correct.  I should have ommitted my first sentence and emphasized the second.  :-)

-- 
D'Arcy J.M. Cain <darcy at druid.net>         |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.
--
http://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list