Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
guys, spoiler flag...
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
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.This comment is hidden because it contains spoiler information about the solution
Because it doesn't. Try printing the input array and check in which cases your code doesn't work.
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.
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.
KeyError
means accessing a structure by non-existent key. I assume that you have abinary
dict and there's simply no entry in it saved under the key4
.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 aquestion
.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