How to fix my Python3 code?

2 posts Thu, Apr 25, 2024 at 07:29 PM edited Apr 26, 2024 at 09:20 AM in New Here & Getting Started

Definition

Class: EqualizeBags
Method: check
Parameters: integer, tuple (integer), integer
Returns: string
Method signature: def check(self, N, bags, E)

Coding Area

class EqualizeBag(object):

    def check(self, N, bags, E):
        t=0
        for c in bags:
            t=t+c
        (q,r)=divmod(t-E,N)
        if r>0:
            return "impossible"
        if min(bags) >= q:
            return "possible"
        return "impossible"

During the contest I got this error and I was unable to figure out what is wrong with my code.
When I press the “Test” button I get the following error message.

Test Results

Correct Return Value: No

Answer check result: 
Result must be not null.

Execution Time: 0.014s

Peak memory used: 22.383MB

abnormal termination (exit 1)

Standard Output:


Standard Error:
Traceback (most recent call last):
  File "Wrapper.py", line 200, in <module>
AttributeError: module 'EqualizeBags' has no attribute 'EqualizeBags'

I have found that my class name was wrong. I had forgotten the little s at the end of the class name. The correct code is as following. Now the code passes the tests.

Solution

class EqualizeBags:

    def check(self, N, bags, E):
        t=0
        for c in bags:
            t=t+c
        (q,r)=divmod(t-E,N)
        if r>0 or q<0:
            return "impossible"
        if min(bags) >= q:
            return "possible"
        return "impossible"

View: Threaded  |  Flat
+0
Sign In or Register to comment.