Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Asha saves 45 rupees every week, and has 0 at the start. She wants a game that costs 300 rupees. Write a while loop that finds after how many weeks she can buy it, and shows how much she has then.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Plan. We do not know the number of weeks, so use a while. The loop continues while she has less than 300.
savings = 0 and weeks = 0.savings < 300.savings, and 1 to weeks.Check. After 6 weeks she has 270, which is less than 300. After 7 weeks she has 315, which is at least 300, and the loop stops.
Answer: 7 weeks, with 315 rupees.
Log in to join the discussion.
Loading…