Why is __name__ == "__main__" not working?

What can be done to code this dynamically? How to fix the design flaw here?

  • Here is the problem statement: https://www.hackerrank.com/contests/oct13/challenges/chocolate-feast def wrapper(): testcases=input() for i in range(testcases): a=list(map(lambda x:int(x), raw_input().split())) choco=a[0]/a[1] last=a[2] test(choco, last) def test(choco, last): p=choco+1 if choco==last: printer(p) elif choco<last: printer(p-1) else: test(choco-last, last)# design isn't right, it is printing 2 for 6 6 2 i.e, not 3+2 to give 5 but just 2. Need to find some way to add dynamically! def printer(x): print x if __name__=='__main__': wrapper() 2) Secondly, in dynamic programming I'm very poor at designing the code. As you can see in the above solution. How can I overcome this?

  • Answer:

    This problem can be solved like this for T in xrange(int(raw_input())): N, C, M = map(int, raw_input().split()) maxChocs = N // C result = maxChocs while maxChocs >= M: temp = maxChocs // M result += temp maxChocs %= M maxChocs += temp print result

Sakthipriyan Vairamani at Quora Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.