Content · Programming · Python

Python Checkpoint: Numbers, Statistics, and Randomness

Check that you can select numeric tools based on the question rather than their names.

2 views Published Oct 17, 2026 Updated Oct 18, 2026 Admin

Check that you can select numeric tools based on the question rather than their names.

What It Does and Why It Matters


A calculation usually starts by deciding whether the answer should be exact, approximate, statistical or random. Decimal is useful for decimal financial rules, Fraction for exact ratios, math for scalar numerical operations, and statistics for summaries. The random module supports simulations but not cryptographic tokens.

A checkpoint is complete when you can predict outputs, justify data types and change sample inputs without breaking the program.

Step-by-Step Example


Start with the complete example below. Read the inputs and predict what the final print statement will show before you run it.

from decimal import Decimal
from fractions import Fraction
import statistics
print(Decimal("0.1") + Decimal("0.2"))
print(Fraction(1, 3) + Fraction(1, 6))
print(statistics.median([1, 2, 100]))

How the Code Works


  • The imports make these standard-library tools available: decimal, fractions, statistics.
  • The print calls display the results. Compare these results with the method’s documented return type and the input used.

Expected output:

0.3
1/2
2

Each displayed line comes from the corresponding calculation or check. The output helps verify the return values before you adapt the example to your own input.

What to Notice


Pay attention to the accepted input types, the returned value and the boundary behavior. Predict what changes if you replace the example input with an empty, zero, negative or missing value, where that value is meaningful for this operation.

If the task uses a library function, inspect its documented exceptions and return type before reusing it inside a larger function.

Where You Would Use This


Use the technique when it makes a real task easier to understand or safer to maintain. Check input and output behavior with small tests before combining it with larger application code.

Practice Exercise


Write a short report containing one Decimal total, one exact Fraction and one median; explain your choices.

Before running your edited example, write down the result you expect. Then test at least one valid boundary or deliberately invalid value, using appropriate exception handling where necessary.

Reference: official Python documentation for the complete API contract and version notes.

Common Beginner Mistakes


  • Choosing a library solely because a function exists, without checking precision, assumptions or boundary cases.
  • Overlooking the documented condition: the random module supports simulations but not cryptographic tokens.

Key Takeaways


  • Check that you can select numeric tools based on the question rather than their names.
  • A calculation usually starts by deciding whether the answer should be exact, approximate, statistical or random.
  • Write a short report containing one Decimal total, one exact Fraction and one median; explain your choices.
Share this resourceSend this page to someone who may find it useful.