Rounding to the nearest 5

David david at abbottdavid.com
Fri Jan 30 15:50:55 EST 2009


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 = int(x)/5
     x = round(x)
     x = x*5
     print int(x)

round_by_5(sys.argv[1])


-- 
Powered by Gentoo GNU/LINUX
http://www.linuxcrazy.com
pgp.mit.edu




More information about the Python-list mailing list