for loop

mensanator at aol.com mensanator at aol.com
Mon Oct 22 18:37:10 EDT 2007


On Oct 22, 5:22 pm, Marc 'BlackJack' Rintsch <bj_... at gmx.net> wrote:
> 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

Also, I would guess that you want to print p, not days.




More information about the Python-list mailing list