Thinking like a programmer
Name ______________ Date ____________
Computer Science Education Week is held in December. A programmer writes an algorithm: exact steps that solve a problem. A computer follows steps exactly, so a missing or wrong step causes a bug. A loop repeats steps, which saves writing. A condition lets a program choose: if the answer is yes, do one thing, and if it is no, do another.
Answer from the reading and your own thinking.
- What is an algorithm?a) A kind of bugb) A guess about the answerc) Exact steps that solve a problem
- A computer fills in a missing step by guessing.TrueFalse
- Start at 0. Repeat 5 times: add 3. What is the result?
- What comes next? 3, 6, 12, 24, ___
- Goal: start with 4, add 10, then double to get 28. The steps are: 1. Start with 4. 2. Double it. 3. Add 10. How do you fix the bug?a) Swap steps 1 and 2b) Swap steps 2 and 3c) Remove step 1
- Rule: if a number is even, divide by 2. If it is odd, add 1. Start with 7 and use the rule twice. What is the result?
- You need the same steps to draw 20 squares. What is best?a) Use a loopb) Write the steps 20 timesc) Draw one square
In two or three sentences, explain why a computer needs exact steps.