A Small Simulation: Putting It Together

Part of: Programming Lab: Python for CSP

Modeling Something Step by Step A simulation models a real process by stepping through it one round at a time. It brings together everything in this lab: variables, input, conditionals, a loop, and a clear final output. Each round updates the state, and when the rounds end you report the result. A Savings Simulation Suppose you start with some savings and add a fixed amount each week. You want to know how many weeks it takes to reach a goal. That is a simulation: repeat a step (one week passing) until a condition is met (savings reach the goal). The state here is savings and weeks. Each pass of the while loop is one week: savings grow by the weekly amount and the week count goes up by one. The loop stops the moment savings reach the goal, and you print how many weeks that took. Watch the Starting State Edge cases matter. If start already meets the goal, the condition savings < goal is False right away, so the loop body never runs and the answer is 0 weeks. Thinking through that boundary before you run is exactly the testing habit good programmers build. Choosing a positive weekly amount also guarantees the loop makes progress and ends. Key takeaways: - A simulation steps through a

Challenge: Weeks to Goal