[Tutor] HELP!!!!

Bob Gailer ramrom@earthling.net
Sat Feb 8 18:40:40 2003


--=======34EE55F1=======
Content-Type: text/plain; x-avg-checked=avg-ok-2E59145B; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 8bit

At 06:20 PM 2/8/2003 -0500, you wrote:
>Sure, this is what I have so far:
>n = 1
>amount = input("What is your initial deposit?  ")
>p = input("Please enter your interest rate  ")
>while amount < 1000000:
>       amount = amount(1 + p/100)**n
>       n = n + 1
>print n, "years"
>print amount
>
>this is what I get along with this error message:
>What is your initial deposit?  1000
>Please enter your interest rate  10
>Traceback (most recent call last):
>   File "C:\Python22\million.py", line 5, in ?
>     amount = amount(1 + p/100)**n
>TypeError: 'int' object is not callable

1) in amount = amount(1 + p/100)**n the parentheses after amount look like 
a function call. Amount isn't a function, its an int, so you get the 
TypeError. If you want multiplication, use an *: amount = amount*(1 + p/100)**n

2) assuming that the user enters an integer for interest, p/100 becomes 
integer division resulting in 0; amount will never change.
So try amount = amount*(1 + p/100.0)**n

3) 1 + p/100.0 is a "loop invariant", meaning that the result is the same 
each pass through the loop. In this program it does not matter; as programs 
grow it can help with efficiency to move such calculations outside the loop:
rate = 1 + p/100.0
while ...
   amount = amount*rate**n

Also when replying please include tutor@python.org so everyone can see your 
messages.

Also as has been mentioned, use a meaningful subject line.

Bob Gailer
mailto:ramrom@earthling.net
303 442 2625

--=======34EE55F1=======
Content-Type: text/plain; charset=us-ascii; x-avg=cert; x-avg-checked=avg-ok-2E59145B
Content-Disposition: inline


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.445 / Virus Database: 250 - Release Date: 1/21/2003

--=======34EE55F1=======--