DEV Community

Cover image for My Approach to Solving Python Logical Problems.
Narasimma Radhakrishnan
Narasimma Radhakrishnan

Posted on

My Approach to Solving Python Logical Problems.

Chocolate Wrapper Problem

I have ₹100. One chocolate costs ₹5. Every time I buy a chocolate, I get one wrapper. I can exchange 3 wrappers for 1 additional chocolate.

What is the maximum number of chocolates I can get?

Total money = ₹100
One chocolate = ₹5
3 wrappers = 1 chocolate
Every new chocolate gives 1 wrapper.


m = 100
c = 5

chocolates = m // c
wrappers = chocolates

while wrappers >= 3:
    new_chocolates = wrappers // 3
    chocolates = chocolates + new_chocolates

    remaining = wrappers % 3
    wrappers = new_chocolates + remaining

print("Total Chocolates:", chocolates)
Enter fullscreen mode Exit fullscreen mode
Total Chocolates: 29
Enter fullscreen mode Exit fullscreen mode

Top comments (0)