[Tutor] TypeError: range() integer end argument expected, got float.
Dominik George
nik at naturalnet.de
Fri Nov 29 22:26:47 CET 2013
Hi,
> Using python 7.3
I think we must update 'import antigravity' to say something about
python-driven flux capacitors :þ ...
> def PaymentTable(balance, annualInterestRate, payment):
You should not CamelCase function names.
> upperbound = round((balance + (monthlyinterest * 12)) / 12, 0)
Your error is because round() does not cast to int. It produces an
integer number in a strict mathematical sense, but not as a data type.
Use int() for that.
> for payment in range(lowerbound, upperbound, 10):
> if PaymentTable(balance, annualInterestRate, payment) == True: ####Error occurs at this line
> print 'Lowest Payment: ', payment
> break
A few notes about that.
1. You mentioned above that you use Python 7.3. As already said, I do
not know what that is, because right now there is Python 2.x and 3.x. I
assumed you meant 3.3, because that is widely used, but in that case,
your print statement would not work. print() is a function, please get
used to that.
2. Do not compare with True. Either the expression is True, or it is
False. No need to be redundantly explicit ;).
3. There might be a more pythonic way to find the lowest payment. List
comprehensions and min() come to mind; however, due to your naming
conventions I do not fully understand what the code is supposed to find.
Something called PaymentTable is supposed to return a table-like thing,
not a boolean. Maybe you should get a bit more into detail about that
(comment your code, for example ;)) and help us give you more hints on
it.
Cheers,
Nik
--
* mirabilos is handling my post-1990 smartphone *
<mirabilos> Aaah, it vibrates! Wherefore art thou, demonic device??
PGP-Fingerprint: 3C9D 54A4 7575 C026 FB17 FD26 B79A 3C16 A0C4 F296
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 905 bytes
Desc: Digital signature
URL: <http://mail.python.org/pipermail/tutor/attachments/20131129/4ee8c12d/attachment.sig>
More information about the Tutor
mailing list