population increasewe

Thread Solved

Join Date: Nov 2009
Posts: 33
Reputation: jaison2 is an unknown quantity at this point 
Solved Threads: 2
jaison2 jaison2 is offline Offline
Light Poster

population increasewe

 
0
  #1
Nov 21st, 2009
The function has to show the population for year 1, 2 and so on until the population reaches 1 million. The population increases by 8% every year?
  1. def population():
  2. current=input("please enter the current population of the city: ")
  3. increase=current/100*8+current
  4. year 1=increase
  5.  
  6. while increase>1000000?
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 64
Reputation: Mathhax0r is an unknown quantity at this point 
Solved Threads: 15
Mathhax0r Mathhax0r is offline Offline
Junior Poster in Training
 
0
  #2
Nov 21st, 2009
  1. def population_growth(argBase, argMax, argRate):
  2. assert argBase < argMax
  3. assert argRate > 0
  4. theAnswer = [argBase]
  5. iterAnswer = argBase
  6. while True:
  7. iterAnswer *= 1+argRate
  8. theAnswer.append(iterAnswer)
  9. if iterAnswer > argMax:
  10. break
  11. return theAnswer
  12. uBasePop = int(raw_input("Enter the base population: "))
  13. print population_growth(uBasePop, 1000000, .08)
I didn't know what you're needs were so I made it fairly abstract. Is this what you're looking for?
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 33
Reputation: jaison2 is an unknown quantity at this point 
Solved Threads: 2
jaison2 jaison2 is offline Offline
Light Poster
 
0
  #3
Nov 22nd, 2009
Originally Posted by Mathhax0r View Post
  1. def population_growth(argBase, argMax, argRate):
  2. assert argBase < argMax
  3. assert argRate > 0
  4. theAnswer = [argBase]
  5. iterAnswer = argBase
  6. while True:
  7. iterAnswer *= 1+argRate
  8. theAnswer.append(iterAnswer)
  9. if iterAnswer > argMax:
  10. break
  11. return theAnswer
  12. uBasePop = int(raw_input("Enter the base population: "))
  13. print population_growth(uBasePop, 1000000, .08)
I didn't know what you're needs were so I made it fairly abstract. Is this what you're looking for?
yeah i havnt learned any of the operations you have put on here such as argbase, append etc... i need to use a while loop and display the results till it reaches 1million..... thx for the help
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 33
Reputation: jaison2 is an unknown quantity at this point 
Solved Threads: 2
jaison2 jaison2 is offline Offline
Light Poster
 
0
  #4
Nov 22nd, 2009
here is my current code.. but it seems to work fine for the first year.. but the second year i want it increase 8% from the 1st year.. hw could i do tht?
  1. def population():
  2. current=input("please enter the current population of the city: ")
  3. increase=current/100*8+current
  4. i=0
  5. while i<1000000:
  6. i=i+increase
  7. print "The population is", i
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,659
Reputation: vegaseat is a glorious beacon of light vegaseat is a glorious beacon of light vegaseat is a glorious beacon of light vegaseat is a glorious beacon of light vegaseat is a glorious beacon of light 
Solved Threads: 1089
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite
 
0
  #5
Nov 22nd, 2009
You have to put your increase calculation in the loop.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 17
Reputation: tbone2sk is an unknown quantity at this point 
Solved Threads: 7
tbone2sk tbone2sk is offline Offline
Newbie Poster
 
0
  #6
Nov 22nd, 2009
  1. def population():
  2. current=input("please enter the current population of the city: ")
  3. yearCount = 1
  4. print "At year 0 The population is ",current
  5. while current < 1000000:
  6. current += current*0.08
  7. print "At year ",yearCount,"The population is ",current
  8. yearCount += 1
  9. if __name__ == '__main__':
  10. population()
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 33
Reputation: jaison2 is an unknown quantity at this point 
Solved Threads: 2
jaison2 jaison2 is offline Offline
Light Poster
 
0
  #7
Nov 22nd, 2009
yearCount += 1
if __name__ == '__main__':
population()[/CODE]
can you just tell me about what is happening in these lines?
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 17
Reputation: tbone2sk is an unknown quantity at this point 
Solved Threads: 7
tbone2sk tbone2sk is offline Offline
Newbie Poster
 
0
  #8
Nov 22nd, 2009
It is just a
  1. def main():
  2. main()
for testing the function population. Then all I do is call population(). If those 2 lines of code where not present then the function population would never run.
Also the yearCount is just totaling up the years.
yearCount += 1 is the same as yearCount = yearCount + 1
Last edited by tbone2sk; Nov 22nd, 2009 at 11:58 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 243
Reputation: masterofpuppets is an unknown quantity at this point 
Solved Threads: 70
masterofpuppets's Avatar
masterofpuppets masterofpuppets is offline Offline
Posting Whiz in Training
 
0
  #9
Nov 22nd, 2009
here's a more general version of this :

  1. def population( start, maxPop, rate ):
  2. start += ( ( float( rate ) / 100 ) * start )
  3. year = 1
  4. while start <= maxPop:
  5. print year, "-", int( start )
  6. start += ( ( float( rate ) / 100 ) * start )
  7. year += 1
  8.  
  9. startPop = input( "Enter base population: " )
  10. lim = input( "Enter population limit: " )
  11. rate = input( "Enter rate of change in %, ( e.g. 8 ): " )
  12.  
  13. population( startPop, lim, rate )
My site ->> http://8masterofpuppets8.webs.com/
"My belief is stronger than your doubt."
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 33
Reputation: jaison2 is an unknown quantity at this point 
Solved Threads: 2
jaison2 jaison2 is offline Offline
Light Poster
 
0
  #10
Nov 22nd, 2009
Originally Posted by tbone2sk View Post
It is just a
  1. def main():
  2. main()
for testing the function population. Then all I do is call population(). If those 2 lines of code where not present then the function population would never run.
Also the yearCount is just totaling up the years.
yearCount += 1 is the same as yearCount = yearCount + 1
if __name__ == '__main__':, is this the sam as saying def main()? and could you please tell me what you mean by totaling up the years?.. i understand the current+=current*0.08, this means that it does the interest on the predecessor and not the actual value which we have put in right?
Last edited by jaison2; Nov 22nd, 2009 at 2:32 pm.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum


Views: 569 | Replies: 10
Thread Tools Search this Thread



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

©2003 - 2010 DaniWeb® LLC