Plz help me with HW, Python For Loop

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2008
Posts: 4
Reputation: urmybaby is an unknown quantity at this point 
Solved Threads: 0
urmybaby urmybaby is offline Offline
Newbie Poster

Plz help me with HW, Python For Loop

 
0
  #1
Apr 25th, 2008
Enter initial capital: 2000
Enter percentage: 6.6
Enter number of years: 4
After Year 1 you’ll have 2132.0 dollars
After Year 2 you’ll have 2272.71 dollars
After Year 3 you’ll have 2422.71 dollars
After Year 4 you’ll have 2582.61 dollars
In 4 years, a total interest of 582.61 dollars is paid

above should be the output

initial_capital = float(raw_input("Enter initial capital: "))
percentage = float(raw_input("Enter percentage: "))
year = float(raw_input("Enter number of years: "))
c = initial_capital
r = percentage
r = r/100.00
year = 0
i = c*r
for i in range(year+1,):
c=c*(1+r)
year=year+1
i=c-initial_capital
print "After year",year,"you'll have",c,"dollars"
print "In",year,"years, a total interest of",i,"dollars is paid"

above is my input, result is only showed year 1, rest of years is not showing up
can anyone help me plz thank you.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 15
Reputation: jaux is an unknown quantity at this point 
Solved Threads: 2
jaux's Avatar
jaux jaux is offline Offline
Newbie Poster

Re: Plz help me with HW, Python For Loop

 
0
  #2
Apr 25th, 2008
Please use [code=python] tag to enclose your code, so we can see the indent.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 1,546
Reputation: Ene Uran has a spectacular aura about Ene Uran has a spectacular aura about 
Solved Threads: 174
Ene Uran's Avatar
Ene Uran Ene Uran is offline Offline
Posting Virtuoso

Re: Plz help me with HW, Python For Loop

 
0
  #3
Apr 25th, 2008
If you set year=0 and then use range(year+1), you only go once through your loop.
drink her pretty
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Python Forum
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC