help with a function
Paul McGuire
ptmcg at austin.rr._bogus_.com
Tue May 16 22:33:54 EDT 2006
"Lance Hoffmeyer" <lance at augustmail.com> wrote in message
news:446a85c6$0$61170$ae4e5890 at news.nationwide.net...
> Hey all,
>
> I'm new to python. I keep getting an error when running this.
> I'm sure there is an easy fix but I can't figure it out.
> What am I doing wrong? How do I fix it?
>
> def even_odd_round(num):
> if(round(num,2) + .5 == int(round(num,2)) + 1):
> if(int(num,0) % 2): #an odd number
> rounded_num = round(num,2) + .1
> else: #an even number
> rounded_num = round(num,2) - .1
> rounded_num = int(rounded_num)
> return rounded_num
>
> even_odd_round(5.5)
>
> Traceback (most recent call last):
> File "<interactive input>", line 1, in ?
> File "<interactive input>", line 3, in even_odd_round
> TypeError: int() can't convert non-string with explicit base
> >>>
1 def even_odd_round(num):
2 if(round(num,2) + .5 == int(round(num,2)) + 1):
3 if(int(num,0) % 2): #an odd number
4 rounded_num = round(num,2) + .1
5 else: #an even number
6 rounded_num = round(num,2) - .1
7 rounded_num = int(rounded_num)
8 return rounded_num
9
10 even_odd_round(5.5)
> Traceback (most recent call last):
> File "<interactive input>", line 1, in ?
> File "<interactive input>", line 3, in even_odd_round
> TypeError: int() can't convert non-string with explicit base
This
More information about the Python-list
mailing list