Ad
  • Custom User Avatar
  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    You can print(arr) to see the input. As Voile pointed out, the array length is not fixed. The random tests include integers which have "length" of more than 4 bits.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Because it doesn't. Try printing the input array and check in which cases your code doesn't work.

  • Custom User Avatar

    The code works when I run it in VS Code so that's why I was confused. I still don't understand how my code can pass all the tests and still produce an error.

  • Custom User Avatar

    Not every array has 4 elements. It's your code's problem ;-)

    Resolving.

    Edit: also clarified this bit in the descriptions and removed all input modification shenanigans.

  • Custom User Avatar

    KeyError means accessing a structure by non-existent key. I assume that you have a binary dict and there's simply no entry in it saved under the key 4.

    You can post your code, marking the comment as spoiler so somebody could help you with it.

    And please, raise an issue if it's a problem with the kata, your comment is a question.

  • Custom User Avatar

    So for this kata I wrote a solution that did not manipulate the original list. I passed all of the tests but when I go to attempt my soultion I passed all 4 tests and then get an STDERR: error that says this:

    Traceback (most recent call last):
    File "main.py", line 16, in
    Test.assert_equals(binary_array_to_number(array), n,"It should work for random inputs too")
    File "/home/codewarrior/solution.py", line 13, in binary_array_to_number
    num.append(digit * binary[ind])
    KeyError: 4

    Does anyone know how to fix this?
    P.S I did not use the reverse() as I see in other comments