part 4, patterns, algorithms and programs 1 Flashcards
- Start with an if statement
- Use elif statements there after
- Use an else statement as the last statement. This acts as a catch all and does not evaluate any boolean expressions
describe the 3 steps of using pythons elif statement
what are the 3 steps of the formula problem pattern
the first thing to think about here is what inputs are admissible
example
are only positive integers allowed
is there a minimum or maximum input value
when testing code what is the first thing you should think about for the test values
by applying this pattern template to an algorithm we can implement selection between two different cases
what does the case analysis (two cases) pattern allow
- negation (NOT)
- conjunction (AND)
- disjunction (OR)
what are the three most used boolean operations
when testing code what is the first thing you should think about for the test values
the first thing to think about here is what inputs are admissible
example
are only positive integers allowed
is there a minimum or maximum input value
what is floor division
this divides a given number by another given number and then rounds the quotient down to the nearest integer and returns this value
what are the 6 steps of the case analysis (two cases) pattern
what are the 6 steps of the sequence generation pattern
this operation finds out how many times the second number goes into the first and then returns the remainder
what does pythons modulus operator do
when can we apply the formula problem pattern
this can be applied to an algorithm when one or more inputs can directly calculate one output
name some comparison operators in python
what are the three most used boolean operations
- negation (NOT)
- conjunction (AND)
- disjunction (OR)
when testing code what is the second thing you should think about
at this stage you should think about any borderline values and what they will be
example
was there a minimum or maximum input value
can input be positive and negative
what are the 9 steps of the problem solving workflow when using pattern templates
this divides a given number by another given number and then rounds the quotient down to the nearest integer and returns this value
what is floor division
when using this. on the last else statement you should include what it will catch but comment it out
when using pythons elif statement what is good practice for the last else statement
this can be applied to an algorithm when there is a value that changes with every iteration and the last iteration is unknown
when can we apply the sequence generation pattern to an algorithm