Exercise · Q5
Q.Suppose you are collecting money for something. You need ₹ 200 in all. You ask your parents, uncles and aunts as well as grandparents. Different people may give either ₹ 10, ₹ 20 or even ₹ 50. You will collect till the total becomes 200. Write the algorithm.
CBSENCERTSubjective· 3mImportance★★★★★est
64% · 23/36 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →A condition-controlled accumulation loop: start total at 0, keep reading each person's gift and adding it, and stop as soon as total reaches 200.
The idea (accumulation). We do not know how many people will contribute — only when to stop (total = 200). That calls for a condition-controlled loop with an accumulator: a variable total that starts at 0 and grows by each input amount. The loop condition total < 200 is checked before every new request, so we stop asking the moment the target is met.
Algorithm
COLLECT_MONEY_ALGO
Step 1: SET total = 0
Step 2: WHILE total < 200, REPEAT Steps 3-4
Step 3: INPUT amount (a person gives 10, 20 or 50)
Step 4: total = total + amount
Step 5: PRINT "Target reached! Total collected =", total
END
Python implementation
total = 0
while total < 200:
amount = int(input("Amount given (10/20/50): "))
total = total + amount
print("Target reached! Total collected =", total)
Dry run for contributions 50, 50, 20, 50, 20, 10:
| Person | amount | total after adding | total < 200? (next test) |
|---|---|---|---|
| 1 | 50 | 50 | yes — ask again |
| 2 | 50 | 100 | yes |
| 3 | 20 | 120 | yes |
| 4 | 50 | 170 | yes |
| 5 | 20 | 190 | yes |
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.