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 →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data 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
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Python Labs
  2. /Probabilities by counting and by chaining
MathematicsEasyHigh School (11–12)Statistics and Probability

Probabilities by counting and by chaining

You will write three small functions: one that finds the probability of an event by counting outcomes, one that finds a conditional probability, and one that multiplies the steps along a path of a tree. The checker uses two dice and a bag of balls.

The idea. For equally likely outcomes, P(A)P(A)P(A) is the number of outcomes in AAA divided by the total. Given BBB, count only inside BBB. Along a path of a tree diagram you multiply the branch probabilities.

Your tasks.

  1. Finish prob(event, space). Count the outcomes for which event(outcome) is true and divide by the size of the space.
  2. Finish given(a, b, space). Return the probability of a given b.
  3. Finish chain(steps). Multiply all the probabilities in the list. An empty list gives 111.

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, use chain to find the probability of drawing red, red, red from a bag of 555 red and 333 blue balls without replacement. The three steps are 58\tfrac{5}{8}85​, 47\tfrac{4}{7}74​ and 36\tfrac{3}{6}63​.

StemPy LabContributed by StemPy Lab
python
Loading Python runtime…

A 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
← Bisectors, bisecting points and volumesIndependent or not →
More onStatistics and Probability

Discussion (0)

Log in to join the discussion.

Loading…

More labs on this topic

  1. Residuals and trapsMedium
  2. Correlation and regression by computerMedium
  3. Quartiles and outliersMedium
  4. Changing and combining dataMedium
  5. Spread by computerMedium
All labs on this topic →