Benjamin J. Racine wrote:
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.
I am learning, I got this to work fine;
#!/usr/bin/python
import sys
def round_by_5(x = sys.argv[1]):
x =
-list-bounces+bjracine=glosten@python.org
[mailto:python-list-bounces+bjracine=glosten@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@python.org
Subject: Re: Rounding to the nearest 5
On 30 Jan 2009 06:23:1
On 30 Jan 2009 06:23:17 GMT
Steven D'Aprano 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
em
todp...@hotmail.com wrote:
> How can you make python round numbers to the nearest 5:
>
> Example:
>
> 3 => 0
> 8 => 10
> 23.2 => 20
> 36 => 35
> 51.5 => 50
round(n,-1) rounds to the nearest 10, so
round(n*2,-1)/2 will round to the nearest five.
Gary Herron
>
>
> Thanks!
>
> -
Steven D'Aprano wrote:
On Thu, 29 Jan 2009 18:26:34 -0600, Tim Chase wrote:
How can you make python round numbers to the nearest 5:
Example:
3 => 0
8 => 10
23.2 => 20
36 => 35
51.5 => 50
I'm not sure *any* rounding system will give those results.
Round towards zero.
8 => 10 ?
One ca
On Fri, 30 Jan 2009 00:24:47 -0500, D'Arcy J.M. Cain wrote:
> On Thu, 29 Jan 2009 16:06:09 -0800
> "todp...@hotmail.com" wrote:
>> How can you make python round numbers to the nearest 5:
>>
>> Example:
>>
>> 3 => 0
>> 8 => 10
>> 23.2 => 20
>> 36 => 35
>> 51.5 => 50
>
> That appears to be rou
On Thu, Jan 29, 2009 at 7:26 PM, Tim Chase wrote:
>> How can you make python round numbers to the nearest 5:
>> Example:
>> 3 => 0
>> 8 => 10
>> 23.2 => 20
>> 36 => 35
>> 51.5 => 50
>
> I'm not sure *any* rounding system will give those results.
def bogoround(n):
n1 = n / 5.0
return int(
On Thu, 29 Jan 2009 16:06:09 -0800
"todp...@hotmail.com" wrote:
> How can you make python round numbers to the nearest 5:
>
> Example:
>
> 3 => 0
> 8 => 10
> 23.2 => 20
> 36 => 35
> 51.5 => 50
That appears to be rounding to nearest 10, not 5. Clarify your
requirements first.
--
D'Arcy J.M.
On Thu, 29 Jan 2009 18:26:34 -0600, Tim Chase wrote:
>> How can you make python round numbers to the nearest 5:
>>
>> Example:
>>
>> 3 => 0
>> 8 => 10
>> 23.2 => 20
>> 36 => 35
>> 51.5 => 50
>
> I'm not sure *any* rounding system will give those results.
Round towards zero.
> 3 should roun
todp...@hotmail.com wrote:
How can you make python round numbers to the nearest 5:
Example:
3 => 0
8 => 10
23.2 => 20
36 => 35
51.5 => 50
Divide by 5, round the result, then multiply by 5.
--
http://mail.python.org/mailman/listinfo/python-list
How can you make python round numbers to the nearest 5:
Example:
3 => 0
8 => 10
23.2 => 20
36 => 35
51.5 => 50
I'm not sure *any* rounding system will give those results. 3
should round up to 5 (not down to 0) and 23.2 should round up to
25 (not down to 20) in the same way that 8 rounds
11 matches
Mail list logo