Introduction: Our first programs π£
The wait is over! Week 0 was about preparing for the course, and Week 1 was about course information and the "Big Picture", but starting now we focus on writing programs.
The goals for the week are for you to become comfortable writing SIPO style programs using Python, and to get some practice in moving from a problem described in English, through a solution procedure described using English to one expressed in Python.
This week we'll move on and begin writing short programs to calculate things. These programs sometimes go by the acronym SIPO to remind us of the operations they use: Sequence, Input, Processing and Output. They are just like sequences of calculator commands placed one after another.
This week we will put the first four (of six) computational constructs to work to write SIPO programs. These are calculator-style programs that use a sequence (S) of instructions to take some data (input or I), process it (P), and display the result (output or O). I say "calculator-style" because the problems are ones people often use calculators for.
While the programs themselves are quite short, they will introduce you to the need to keep three separate things in mind as you program:
- The program code
- What is going on in the computer's memory
- What is displayed on the screen
One of the first challenges in learning to program is to develop the ability to keep all three things in mind as you develop your program.
There are also several points of programming craft that come up for the first, but definitely not the last, time this week, including choosing good variable names, program layout, documentation, and using symbolic constants.
And one arithmetic operator that is very useful in a wide variety of programs, but may be new to you: modulo.
Assignment 1 was somewhat artificial, because I needed a way to know that you had read the things I'd asked you to, and that you had installed Python, but the remaining assignments are more authentic. They will usually ask you to write around 4 small programs, though our idea of what "small" is will grow as the course progresses!
The remaining assignments are more homogeneous than the first one. There won't be more short answer questions, cards to sort, or sculptures to describe, just programs to write from here almost to the end of the course. Four programs most weeks.
- Recall: Programming is...
- The Problem
- Do The Problem By Hand
- Translate the Algorithm into Python
- Enter, run and test the program
- Naming Values
- What will it look like onscreen?
- Documentation
- Our second program (Same as the first only backwards) html#translate-to-python)
- Our third program (dhms2s.py)
- SIPO Summary
- Translate into Python
- Modulo: A Sixth Arithmetic Operator
- Symbolic Constants
- Intermission: Summary (so far)
- Object Types 1:Β
int
s andΒfloat
s - Example: Calculating Tree Radius
- Example: Value of your change
- Example: Making change
- Pythonic Details
- Triple Quoted Strings
- The Continuation Character
- TheΒ
done
Β trick - Output Formatting
- The Pythonic Process
- Exercise sheet 1
- Assignment 2