What does this program print?
for i in range(10): print(i+1)
Let's modify this program incrementally to (by demo)...
That third one is complex enough to use some of the ideas you read in Chapter 3 about designing algorithms and developing programs. We need to think about what we have, and what we would like it to be.
One technique is almost always useful: Break the problem into smaller steps. We have a program that prints the even numbers up to a limit.
This program is more complex than many of us want to write from scratch:
for counter in range(10): n = counter + 1 if n % 2 == 0: result = '' for i in range(n): value = i + 1 if value % 2 == 0: result += (str(value) + ' ') print(result)
But by breaking complex steps down into smaller, more manageable steps, we were able to design a solution. That process also enabled us to grow the program slowly and have a working solution at each point along the way.
With practice, you can do the same.
(Try to think this way on Homework 4.)
Debug these programs.
A look at my solution.
Notes.
There is no 10000 in the specification. Do you know why it's right? Why 100*100? Not all formulas can be adjusted so easily after the fact, and every adjustment makes the reader slow down and work harder than she needs.
This is similar to not pre-compiling values in your program.
The number and order of inputs. 6'-6" versus 78".
Debug these programs.
A look at my solution.
Notes.
Do you understand the compound interest formula? In any case, it is overkill here. We need yearly balance updates, not just the final answer.
No while or for loop? Something may be amiss... The purpose of the assignment was to give you practice with a loop. (It also helps you understand how the compound interest formula works!)
Order of inputs. Filenames.
Grader as user. Automated testing (show).
More general notes.
Even if you add only a print statement. We can break a working program.
In your code: whitespace, names, comments line wrap. In your user interaction: input prompts (space) and print labels.
A big one: Do your own work. Sharing. Finding solutions.