Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7886729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:23:34+00:00 2026-06-03T05:23:34+00:00

I have some formulas that I have defined as functions. I’ve then ‘named’ them

  • 0

I have some formulas that I have defined as functions.

I’ve then ‘named’ them using particular parameters as I then need to use the output in further formula’s which makes it easier and neater.

I now need to loop the defined function to give the outputs for each month over the year, and when I put in the name of the function into the while loop, it just gives me the one answer 12 times over, but when I put the full function into the loop it works.

Is there a way that I can loop the function by using it’s name because as my formulae are progressing, they’re getting more and more complex and the code is getting busy and confusing.

def growPOP(p, T, r, K):
    #formula to calculate the new population at the end of a month.
    #p = initial population, T = total initial population
    #r = growth rate per time, K = carrying capacity
    GrPp = p + ((p * r)*((K - T) / K))
    return(GrPp)

def rt(a, b, t):
    #formula to calculate growth rate for brown fish
    #a & b are constants given, t = the month number
    rt = a + (b*sin(((2*pi)*t)/12))
    return rt

ca = 0.052
cb = 0.132   
brownPOP = 19000
goldPOP = 4400
totalPOP = brownPOP + goldPOP
carryK = 104800
redcarryK = 0.998
newcarryK = (carryK*redcarryK) + (ep/10) #ep is an input figure - for now it's 0.
month = 1
brownGrowth = growPOP(brownPOP, totalPOP, rt(ca, cb, month), carryK)

while month <= 2:
    print "Month ", month
    print "Grown brown fish: ", growPOP(brownPOP, totalPOP, rt(ca, cb, month), carryK)
    brownPOP = endbrownPOP
    goldPOP = endgoldPOP
    totalPOP = endtotalPOP
    carryK = newcarryK
    month = month + 1

So in the above loop it gives me exactly the output I want, but I really want the loop to say “print “Grown brown fish: “, brownGrowth” and still work.

There are other formulae to get brownPOP to endbrownPOP but there’s quite a few and they work, so I didn’t think they needed to be entered in to complicate things.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T05:23:35+00:00Added an answer on June 3, 2026 at 5:23 am

    I think you just forgot to recalculate brownGrowth in every loop iteration?

    brownGrowth = growPOP(brownPOP, totalPOP, rt(ca, cb, month), carryK) 
    while month <= 2: 
        print "Month ", month 
        print "Grown brown fish: ", brownGrowth
        brownPOP = endbrownPOP  
        goldPOP = endgoldPOP  
        totalPOP = endtotalPOP  
        carryK = newcarryK  
        month = month + 1  
    

    Move the brownGrowth = formula line to inside while loop:

    while month <= 2: 
        brownGrowth = growPOP(brownPOP, totalPOP, rt(ca, cb, month), carryK) 
        print "Month ", month 
        print "Grown brown fish: ", brownGrowth
        brownPOP = endbrownPOP 
        goldPOP = endgoldPOP 
        totalPOP = endtotalPOP 
        carryK = newcarryK 
        month = month + 1 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some files that are uuencoded, and I need to decode them, using
I have some PHP code that is designed to make a spreadsheet with formulas
I Have some Formulas in Javascript and trying to format them but unable to
I have an excel spreadsheet that contains some formulas to calculate ROI for an
I have a set of expressions representing some formula with some parameters inside. Like:
I need to have a formula produce a null in some cases, numeric in
I have some script in my default page that redirects users to language specific
I have some jquery code that is doing an ajax lookup and returning comma
I'm converting some excel formulas to another system and need to do some fairly
I'm developing a report in Crystal Reports and need to render some math formulas

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.