for loop

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Mon Oct 22 18:22:44 EDT 2007


On Mon, 22 Oct 2007 18:17:56 -0400, Shawn Minisall wrote:

> #Intro
>     print "*********************************************"
>     print  "WELCOME TO THE POPULATION GROWTH CALCULATOR"
>     print "*********************************************"
> 
>     print "This program will predict the size of a population of organisms."
>     print
>     print
>     organisms=input("Please enter the starting number of organisms: ")
> 
>     increase=input("Please enter the average daily population increase 
> as a percentage (20% = .20): ")
> 
>     days=input("Please enter the number of days that they will multiply: ")
>     
> print "         Day                                    Population"
> print "----------------------------------------------------------"
> 
> 
> for p in range (days):
> 
>     population = organisms * population * increase
> 
>     print days,
> 
>     print "\t\t\t\t",population
> 
> I'm having problems with my for loop here to calculate estimated 
> population output to a table.  Instead of knowing how much I want to 
> loop it, the loop index is going to be whatever number of days the user 
> enters.  When I run my program, it asks the 3 questions above but then 
> just dead stops at a prompt which leads me to believe there's something 
> wrong with my loop.

It should not run at all as it is indented inconsistently.  If that
problem is corrected it will stop with a `NameError` because you try to
read `population` before anything was assigned to it.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list