By the end of this module you can do everything below. The objectives and their wording come from the official PCEP-30-03 syllabus.
5.2.1 Import and use modules
- Explain the purpose and benefits of importing existing code.
- Use the
importkeyword to load a module. - Access objects provided by an imported module.
5.2.2 Perform mathematical evaluations using the math module
- Import and use the
mathmodule. - Round values upward using
ceil(). - Round values downward using
floor(). - Remove the fractional part of a value using
trunc(). - Calculate square roots using
sqrt().
5.2.3 Generate and select pseudorandom values using the random module
- Import and use the
randommodule. - Generate pseudorandom floating-point values using
random(). - Initialize the pseudorandom number generator using
seed(). - Explain how setting a seed can produce repeatable results.
- Select a random element from a sequence using
choice(). - Select multiple unique elements using
sample().