Home > Blockchain >  Array output for shifting left cell isn't matching the verifier even though my answer seems to
Array output for shifting left cell isn't matching the verifier even though my answer seems to

Time:02-03

So I've been trying to solve this code. However, running this code, you'd see that the output says I'm getting the wrong answer. What am I doing wrong here? I'm getting the answer they want but the code is still saying I'm wrong.

k=3
source = [10,20,30,40,50,60]
def shift_left(source,k):
    length = len(source)
    for first in range(k):
        for second in range(0,length-1):
            source[second] = source[second 1]
        source[length-1] = 0
    print(source)
    return None

shift_left(source,k)

print("///  Test 01: Shift Left k cell  ///")
source = [10,20,30,40,50,60]
returned_value = shift_left(source,3) # This should return [40, 50, 60, 0, 0, 0]
unittest.output_test(returned_value, [40, 50, 60, 0, 0, 0])

This is the code I tried. Could someone tell me what I'm doing wrong?

CodePudding user response:

The only return statement in the function is return None.

CodePudding user response:

Instead of:

print(source)
return None

Try:

return source

You are only printing out the correct answer, not returning it. You need to return it.

  • Related