Week 2
Loops
A program can repeat, keep a list, or look something up.
A loop repeats. While keeps going as long as a test stays true. For walks a sequence: the letters of a word, the items in a list, or a range of numbers. Break leaves the loop early. Continue skips to the next round. Len tells you how many things are in a list or a string.
A list keeps items in order. A dict keeps a value under a name, so you can look it up. None means 'no value', which is different from zero and different from an empty string. If you only need to remember one thing while you loop, a single variable is enough. If you need every answer, keep a list.
A fresh example: ask a friend for colors until they say 'stop', and store the colors in a list. That is a loop plus a list. It is not one of the problems.
Problems
- camelCaseWalk the letters. A capital letter starts a new word.
- Coke MachineA loop that keeps asking for a coin and adds only the coins it accepts.
- Just setting up my twttrWalk each letter and drop the vowels.
- Vanity PlatesA list of rules, checked in order. One failure is enough.
- Nutrition FactsA lookup table from a fruit to a number. A long chain of choices is the hard way.