HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →
Live examsInternational live exams are comingTell us which exam you want first. Timed practice papers are open now.See what is coming →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Space Science and Astronomy
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Python Labs
  2. /The forager's calculator
BiologyHardHigh School (11–12)Animal Behaviour and Ethology

The forager's calculator

You will rank prey by profitability and find the best time to stay in a patch that runs down.

The idea. Profitability is E/hE/hE/h. In a patch the gain after ttt seconds is G(1−e−t/k)G(1 - e^{-t/k})G(1−e−t/k), and the rate over a trip is the gain divided by T+tT + tT+t, where TTT is the travel time. The best stay is the one with the highest rate.

Your tasks.

  1. Finish profitability. It gives the energy per second of handling.
  2. Finish best_prey. It takes a list of (name, energy, handling) and gives the name of the most profitable prey.
  3. Finish best_stay. Using trip_rate, which is written for you, try stays from 0.1 s to 200 s in steps of 0.1 s and give the stay with the highest rate.

Run it first, just as it is. The checker at the end prints FAIL for each task. Then do the tasks one at a time, and run the program again after each one. A Hint appears under every check that still fails.

When every line says PASS, call best_stay(120, 60, 20). How long should a bird stay after a two-minute flight?

StemPy LabContributed by StemPy Lab
python
Loading Python runtime…

A worked solution

Run your code once to unlock the worked solution.

Have you tried it?

Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.

Log in to save
← All Labs
← The kin and flock calculatorThe migrant's planner →
More onAnimal Behaviour and Ethology

Discussion (0)

Log in to join the discussion.

Loading…

More labs on this topic

  1. The migrant's plannerHard
  2. The kin and flock calculatorHard
  3. The dance decoderHard
  4. The learning curve labHard
  5. The choice chamber checkerHard
All labs on this topic →