[Tutor] TypeError: range() integer end argument expected, got float.
Steven D'Aprano
steve at pearwood.info
Fri Nov 29 23:16:37 CET 2013
On Fri, Nov 29, 2013 at 02:24:49PM -0500, spinefxr at aol.com wrote:
> Hi
>
>
> Newbie at this. I am getting this error:
> TypeError: range() integer end argument expected, got float.
Note carefully that the error here is with the range() function. In your
code, you have:
> for payment in range(lowerbound, upperbound, 10):
> if PaymentTable(balance, annualInterestRate, payment) == True: ####Error occurs at this line
You are mistaken about where the error occurs. It occurs on the
*previous* line, the one that says "for payment in range...".
You have three arguments for range. All three need to be integers (whole
numbers, like 0, 1, 2, ...) not floats (numbers with decimal points like
2.5, 5.25, or even 7.0). Even if the fraction part is "point zero",
Python will insist it is a float.
You have two solutions here: the best one is to go back to where you
define lowerbound and upperbound and make sure they are whole numbers
with no decimal point.
The less-good solution is to change the line to this:
for payment in range(int(lowerbound), int(upperbound), 10):
--
Steven
More information about the Tutor
mailing list