Class 25 — Wednesday October 21
Module implementation and usage
Practice makes perfect — Is more than a platitude — Take it to your heart
Look both ways
Agenda
- Function-based chrestomathics
Buddying
Slides
Reddit video
Downloads
- Module uva.py
- Implement a worthwhile module with several functions based on your suggestions
- Tester program rotunda.py
- Needs to be based on your ideas for your ideas on
uva.py
- Module primal.py
- Defines three functions relating to factorization and primality.
- None of the functions should get input or print output.
- Tester program factoid.py
- Performs basic testing of module
primal.py
To do
- Review artifacts and prior function materials.
- Complete Homework 22
- Preview next class activities activities
Module uva
: freestyling
- Implement a module with several functions based on your suggestions
- Use
rotunda.py
to testuva.py
Module primal
: to be submitted to document your participation
- Concerned with integer factorization and primality
y
is a factor ofx
, if the remainder ofx
/
y
is 0.
x
is prime, if its only factors are 1 and itself.
x
andy
are relatively prime, ify
is not a factor ofx
andx
is not a factor ofy
-
Function
is_factor( x, y )
- Parameters
x
andy
are integers. The function returns whethery
is a factor ofx
.
Observation
- The
%
is the Python remainder operator.
Possible algorithm
- Determine remainder of
x
divided byy
- By looking at the remainder we can tell whether to return
True
orFalse
-
Function
is_prime( x )
- Parameter
x
is an integer. The function returns whetherx
is prime.
Questions
- Could
is_factor()
help?
- What are the possible range of values do we need check for being possible factors of
x
.
- Does the function need a loop?
-
Function
are_relative_primes( x, y )
- Parameters
x
andy
are integers. The function returns whetherx
andy
are relatively prime.
Questions
- Could
is_prime()
help?
- Could
is_factor()
help?
- Do we need both of them?
- Does the function need a loop?
Slide show
© 2020 Jim Cohoon | Resources from previous semesters are available. |