[Tutor] about little function
Abdirizak abdi
a_abdi406@yahoo.com
Sat Jun 7 12:55:29 2003
--0-1166050707-1055004827=:58558
Content-Type: text/plain; charset=us-ascii
Hi,
I was working on a program that combines a list of values such as this list List = [1,2,3,5,6...] and it also does some computation such as the folowing in the function :
def combine(list_probabilities):
""" it combines the probabilty of list items"""
p1 = 1.0
p2 = 1.0
#print list_probabilities
for i in list_probabilities:
#print i
p1 = p1 * i
p2 = p2 * (1.0 - i)
result = p1 / (p1 + P2)
return result
Problem: when I try to run the program it gives me type error such as the following :
Traceback (most recent call last):
File "classifier.py", line 202, in ?
sw.isSpam(text)
File "classifier.py", line 140, in isSpam
score = combine(list)
File "classifier.py", line 36, in combine
p1 = p1 * i
TypeError: unsupported operand type(s) for *: 'float' and 'list'
can anyone help me why it is giving me this error, when I try on python interactive it works but in the program it doesn't.
thanks in advance
---------------------------------
Do you Yahoo!?
Free online calendar with sync to Outlook(TM).
--0-1166050707-1055004827=:58558
Content-Type: text/html; charset=us-ascii
<DIV>Hi,</DIV>
<DIV>I was working on a program that combines a list of values such as this list List = [1,2,3,5,6...] and it also does some computation such as the folowing in the function :</DIV>
<DIV> </DIV>
<DIV><FONT color=#7f003f>def combine(list_probabilities):<BR> """ it combines the probabilty of list items"""<BR> p1 = 1.0<BR> p2 = 1.0<BR> #print list_probabilities<BR> for i in list_probabilities:<BR> #print i<BR> p1 = p1 * i<BR> p2 = p2 * (1.0 - i)</FONT></DIV>
<DIV><FONT color=#7f003f> result = p1 / (p1 + P2)<BR> return result</FONT></DIV>
<DIV> </DIV>
<DIV>Problem: when I try to run the program it gives me type error such as the following :</DIV>
<DIV> </DIV>
<DIV><FONT color=#ff409f>Traceback (most recent call last):<BR> File "classifier.py", line 202, in ?<BR> sw.isSpam(text)<BR> File "classifier.py", line 140, in isSpam<BR> score = combine(list)<BR> File "classifier.py", line 36, in combine<BR> p1 = p1 * i<BR>TypeError: unsupported operand type(s) for *: 'float' and 'list'</FONT></DIV>
<DIV> </DIV>
<DIV>can anyone help me why it is giving me this error, when I try on python interactive it works but in the program it doesn't.</DIV>
<DIV> </DIV>
<DIV>thanks in advance</DIV><p><hr SIZE=1>
Do you Yahoo!?<br>
Free <a href="http://us.rd.yahoo.com/mail_us/tag/*http://calendar.yahoo.com">online calendar</a> with sync to Outlook(TM).
--0-1166050707-1055004827=:58558--