0
Failed in test cases
Given a list of numbers, this is how Andy like to slice it: If the length of the list is even, extract the n elements from the start If the length of the list is odd, extract n elements from the end Here, n denoted the half of the length of the given list. def solve(Andy_list): n=int(len(Andy_list)/2) if(len(Andy_list)%2==0): Andy_list=Andy_list[0:n-1] else: Andy_list=Andy_list[n+1:-1] return Andy_list
10 Respostas
+ 6
Have you tried to print out your created lists? That might give you a hint what's going wrong.
+ 4
You have to call the function with an actual list, and print out the result.
You should read up a bit on how Python works, the tutorial here wipl quickly get you there!
+ 4
You can test like this, put it after your code.
# Testing
Andy_list = (1, 2, 3, 4, 5, 6)
print (solve(Andy_list))
Andy_list = (1, 2, 3, 4, 5)
print (solve(Andy_list))
+ 1
Gnana Divya There's no single print statement anywhere in your code so there won't be any output. You need to do as Paul Jacobs told you and use
print(solve(Andy_list))
to get your output.
0
Yaaw I just tried the above code in code playground....
It doesn't giving any output
0
I called the function
Like
Andy_list=[1,3,5,7,8]
solve(Andy_list)
0
But not worked
0
Make a code file in Code Playground, complete with function, list creation, call and output, then link it here.
0
I used return statement
0
sorry but your logic is wrong
def solve(Andy_list):
n = int(len(Andy_list))
if(n%2 == 0):
n = n//2
Andy_list = Andy_list[ :n]
return(Andy_list)
else:
n = (n-1)//2
Andy_list = Andy_list[-n: ]
return(Andy_list)
try executing this you will definitely get the output