Python: division error

Heres my method:

def geometricSum(commonRatio, firstTerm, lastTerm):
    return ((firstTerm - lastTerm) * commonRatio) / (1 - commonRatio)

Interpreter testing:

    >>> geometricSum(1.0,1.0,100.0)
    Traceback (most recent call last):
      File "<interactive input>", line 1, in <module>
        File "F:\PortablePython_1.1_py3.0.1\sumOfGeometric.py", line 2, in geometricSum
          return ((firstTerm-lastTerm)*commonRatio)/(1-commonRatio)
    ZeroDivisionError: float division

Answers


You're dividing by zero. commonRatio is 1.0 so the denominator is 1-1.0 = 0.


Need Your Help

Error using __ldg in cuda kernel at compile time

c++ cuda

My goal is to take advantage of cache memory in my application and searching for online examples shows that using __ldg should be relatively straightforward.

Loading a facebox modal window after an ajax request

php ajax codeigniter modal-dialog facebox

this is what i have in the head tags of my html page to load the facebox plugin:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.