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. /Warning, evacuation and cost in code
Earth and Environmental ScienceMediumHigh School (9–10)Natural Hazards

Warning, evacuation and cost in code

You will write three functions for managing a hazard: the seconds of warning of an early warning system, the hours that an evacuation needs, and the benefit-cost ratio of a measure.

The idea. The S waves travel at 3.5 km/s3.5\ \text{km/s}3.5 km/s, so a town at distance ddd gets d/3.5−talertd / 3.5 - t_{\text{alert}}d/3.5−talert​ seconds of warning, and none if this is negative. An evacuation needs people divided by the rate. The ratio is (chance ×\times× loss avoided) divided by (cost divided by years).

Your tasks.

  1. In warning_seconds, return the seconds of warning for a town d km from the focus when the alert comes alert seconds after the start. Return 0 if there is no warning.
  2. In evacuation_hours, return the hours needed to move people people at rate people each hour.
  3. In benefit_cost, return the benefit-cost ratio for a chance, a loss avoided, a total cost and years of use.

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, find the ratio for a measure with a chance of 0.050.050.05, a loss avoided of 808080, a cost of 303030 and a life of 252525 years.

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
← Risk, energy and chance in codeLocating an earthquake from three stations →
More onNatural Hazards

Discussion (0)

Log in to join the discussion.

Loading…

Learn it in

  1. Preparing, responding and recoveringRisk, Warning and Preparation: Managing Hazards

More labs on this topic

  1. Risk, energy and chance in codeEasy
  2. Peak flow and rainfall deficit in codeMedium
  3. Cyclone categories and wind pressure in codeEasy
  4. A tsunami coming ashore in codeMedium
Buildings, soil and resonance in codeEasy
All labs on this topic →