[ZO-Coll] [ZOC] 294/ 2 Reject "unsupported operand type(s) for /"

Collector: NEW Zope.org (the ... zope-web at zope.org
Wed Nov 19 18:31:28 EST 2003


Issue #294 Update (Reject) "unsupported operand  type(s) for /"
 Status Rejected, functionality/bug medium
To followup, visit:
  http://collector.zope.org/ZopeOrg/294

==============================================================
= Reject - Entry #2 by dtremea on Nov 19, 2003 6:31 pm

 Status: Pending => Rejected

> i = 1 / periods
> 
> When I test the script, I get the page asking for the value for periods.
> I put in 10. I then get this error:
> 
> Error Type: TypeError
> Error Value: unsupported operand type(s) for /

You're trying to divide an integer by an string...

> I then changed this statement from-
> i = 1 / periods
> to
> i = 1 / 10
> 
> it ran but the printed output was 0 and not .1

Integer divisions always returns the floor...
 
> I am guessing that the variable i needs to be set to 
> something that I don't know about (I have 15+ years 
> of C but 2 days experience of python)
> Am I doing something wrong? I pasted in the example 
> and expected it to run but ran into this...

Take a look at...

http://www.python.org/doc/current/tut/node5.html

... and this could help you:

i = 1 / float(periods)

;-)
________________________________________
= Request - Entry #1 by wchris on Nov 19, 2003 6:00 pm

I am going through "The Zope Book" to learn ZOPE and have been trying to run the Interest Rate example in particular the script (python) object. I have gutted most of the lines and now just have this in the Script (python) object:
""" 
Calculate compounding interest.
"""

i = 1 / periods
print i

return printed

When I test the script, I get the page asking for the value for periods. I put in 10. I then get this error:

Error Type: TypeError
Error Value: unsupported operand type(s) for /

I then changed this statement from-
i = 1 / periods
to
i = 1 / 10

it ran but the printed output was 0 and not .1

I am guessing that the variable i needs to be set to something that I don't know about (I have 15+ years of C but 2 days experience of python) Am I doing something wrong? I pasted in the example and expected it to run but ran into this...

By the way, If I change the operand to a * :
i = 1 * periods
it works just fine. It seems that the / is giving me grief.

Thanks....

==============================================================




More information about the Zopeorg-collector mailing list