Class 24 — October 18
Form with function
The Jersey cow moos — Is that to be its function — The Paw Patrol knows
Practice makes perfect — Is more than a platitude — Take it to your heart
Look both ways
- Start function-based chrestomathics
Top-down design – problème de la journée
- Translate multi-line text using the babel translation dictionary
- Module polyglot.py
- Provides support for text translation
- Program use-polyglot.py
- Gets user text needing translation
- Program cauldron.py
- Gets URL text needing translation
Discussion — why have functions
- Complex problem solving requires that we break a problem down into tasks that when put together, solve the problem. If the component tasks are also complex, the breaking down process can be repeated to determine the sub-tasks needed for solving the major tasks.
- This form of problem solving is called top-down design; there is also bottom-up design and object-oriented design. Object-oriented design is the focus of the second course in digital problem solving at UVA.
- In digital problem solving, the component tasks are written as independent units of code. For clarity, code units are named so that there is no ambiguity as to what unit is being considered. In Python we call a named unit of code, a function.
- We use functions to provide an easier, clearer, and often reusable way for the manipulation and calculation of values. In designing a function we need to determine
- What information is needed upon startup;
- What information it is to produce; and
- Provide an algorithm for going from one to the other.
- Use CodeBat for function practice
- Look over artifacts