Skip to content
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
🔒 Locked · start free trial →

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:

Personamounttotal after addingtotal < 200? (next test)
15050yes — ask again
250100yes
320120yes
450170yes
520190yes

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.