Using
1/3.0
instead
1/3
in your code. Otherwise, your score will always be 0 due to integer truncation.
Whether to use ** or math.pow() depends on your preference, most of them probably just use ** .
It is probably not a good idea to define a function called eval , since eval () is already in use by Python as an inline function.
Background:
Note that you can also do 1.0 / 3 or 1.0 / 3.0 .. as long as one of the operands in the section is float , the result will be float .
However, this float(1/3) will not work, as it converts 0 as a result of integer division 1/3 to float , giving you 0.0
In Python 3.x, the split operator / would work as you would expect (i.e., it would give you a float value even with two integer operands). To get integer division, you need to use // .
So, if you were to run this under Python 3.x, you would not run into this particular problem.
Levon
source share