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
  • Earth and Environmental Science
  • 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. /Reading a population pyramid
Earth and Environmental ScienceEasyHigh School (11–12)Environmental Systems and Sustainability

Reading a population pyramid

Here are the numbers of people in three broad age groups for three towns. You will find the share of children, the dependency ratio and the shape of each pyramid.

The idea. The dependency ratio compares the people who usually do not work (under 15 and 65 or over) with those of working age (15 to 64):

ratio=young+oldworking age×100\displaystyle \text{ratio} = \dfrac{\text{young} + \text{old}}{\text{working age}} \times 100ratio=working ageyoung+old​×100

with young under 15, old 65 and over, and working age 15 to 64.

For this lab, use a simple rule for the shape: a share of children of 30 % or more is expanding, under 18 % is declining, and anything between is stable.

Your tasks.

  1. In share_children, return the percentage of the town's people who are under 15.
  2. In dependency_ratio, return the dependency ratio of the town.
  3. In shape, return "expanding", "stable" or "declining" by the rule above.

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, add a fourth town of your own with many old people. Which shape does it get, and how large is its dependency ratio?

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
← Rain, satellites and sunshine in codeA tiger reserve, year by year →
More onEnvironmental Systems and Sustainability

Discussion (0)

Log in to join the discussion.

Loading…

Learn it in

  1. Population change, growth and its controlPeople, Nature and Population Ecology

More labs on this topic

  1. Terms of trade over a decadeMedium
  2. A footprint calculatorEasy
  3. Rations for one laneEasy
  4. A tiger reserve, year by yearHard
Rain, satellites and sunshine in codeMedium
All labs on this topic →