| | |
population increasewe
Thread Solved |
•
•
Join Date: Nov 2009
Posts: 33
Reputation:
Solved Threads: 2
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?
Python Syntax (Toggle Plain Text)
def population(): current=input("please enter the current population of the city: ") increase=current/100*8+current year 1=increase while increase>1000000?
•
•
Join Date: Aug 2009
Posts: 64
Reputation:
Solved Threads: 15
0
#2 Nov 21st, 2009
Python Syntax (Toggle Plain Text)
def population_growth(argBase, argMax, argRate): assert argBase < argMax assert argRate > 0 theAnswer = [argBase] iterAnswer = argBase while True: iterAnswer *= 1+argRate theAnswer.append(iterAnswer) if iterAnswer > argMax: break return theAnswer uBasePop = int(raw_input("Enter the base population: ")) print population_growth(uBasePop, 1000000, .08)
•
•
Join Date: Nov 2009
Posts: 33
Reputation:
Solved Threads: 2
0
#3 Nov 22nd, 2009
•
•
•
•
I didn't know what you're needs were so I made it fairly abstract. Is this what you're looking for?Python Syntax (Toggle Plain Text)
def population_growth(argBase, argMax, argRate): assert argBase < argMax assert argRate > 0 theAnswer = [argBase] iterAnswer = argBase while True: iterAnswer *= 1+argRate theAnswer.append(iterAnswer) if iterAnswer > argMax: break return theAnswer uBasePop = int(raw_input("Enter the base population: ")) print population_growth(uBasePop, 1000000, .08)
•
•
Join Date: Nov 2009
Posts: 33
Reputation:
Solved Threads: 2
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?
Python Syntax (Toggle Plain Text)
def population(): current=input("please enter the current population of the city: ") increase=current/100*8+current i=0 while i<1000000: i=i+increase print "The population is", i
•
•
Join Date: Nov 2009
Posts: 17
Reputation:
Solved Threads: 7
0
#6 Nov 22nd, 2009
Python Syntax (Toggle Plain Text)
def population(): current=input("please enter the current population of the city: ") yearCount = 1 print "At year 0 The population is ",current while current < 1000000: current += current*0.08 print "At year ",yearCount,"The population is ",current yearCount += 1 if __name__ == '__main__': population()
•
•
Join Date: Nov 2009
Posts: 17
Reputation:
Solved Threads: 7
0
#8 Nov 22nd, 2009
It is just a 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
Python Syntax (Toggle Plain Text)
def main(): main()
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.
0
#9 Nov 22nd, 2009
here's a more general version of this
:
: Python Syntax (Toggle Plain Text)
def population( start, maxPop, rate ): start += ( ( float( rate ) / 100 ) * start ) year = 1 while start <= maxPop: print year, "-", int( start ) start += ( ( float( rate ) / 100 ) * start ) year += 1 startPop = input( "Enter base population: " ) lim = input( "Enter population limit: " ) rate = input( "Enter rate of change in %, ( e.g. 8 ): " ) population( startPop, lim, rate )
•
•
Join Date: Nov 2009
Posts: 33
Reputation:
Solved Threads: 2
0
#10 Nov 22nd, 2009
•
•
•
•
It is just afor 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.Python Syntax (Toggle Plain Text)
def main(): main()
Also the yearCount is just totaling up the years.
yearCount += 1 is the same as yearCount = yearCount + 1
Last edited by jaison2; Nov 22nd, 2009 at 2:32 pm.
![]() |
Similar Threads
- News Story: WoW: population 11 million (Posting Games)
- population program (C++)
- Einwohnerzahl.com & Einwohnerzahl.net (German word for population) (Websites for Sale)
Other Threads in the Python Forum
- Previous Thread: string.split()
- Next Thread: pyqt execution problem...
Views: 569 | Replies: 10
| Thread Tools | Search this Thread |
Tag cloud for Python
application array beginner c++ c/c++ calculator change character class client code command convert count create csv ctypes database dictionary directory django dll error examples excel exe extensions fdlib file float format framework ftp function graphics gui homework image images import input library line linux list lists logging loop loops microcontroller millimeter mouse mysql mysqldb number numbers output parse parsing path port prime processing program programming py2exe pygame pygtk pyqt python random raw_input recursion recursive redirect remote scrolledtext server socket ssh stdout string strings syntax table terminal text thread threading tkinter transparency tuple tutorial ubuntu unicode variable variables web windows wxpython






