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

12th Nov 2019, 8:19 AM
Gnana Divya
10 ответов
+ 6
Have you tried to print out your created lists? That might give you a hint what's going wrong.
12th Nov 2019, 8:45 AM
HonFu
HonFu - avatar
+ 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!
12th Nov 2019, 8:55 AM
HonFu
HonFu - avatar
+ 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))
12th Nov 2019, 9:00 AM
Paul
Paul - avatar
+ 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.
12th Nov 2019, 1:09 PM
Russ
Russ - avatar
0
Yaaw I just tried the above code in code playground.... It doesn't giving any output
12th Nov 2019, 8:51 AM
Gnana Divya
0
I called the function Like Andy_list=[1,3,5,7,8] solve(Andy_list)
12th Nov 2019, 11:10 AM
Gnana Divya
0
But not worked
12th Nov 2019, 11:10 AM
Gnana Divya
0
Make a code file in Code Playground, complete with function, list creation, call and output, then link it here.
12th Nov 2019, 11:53 AM
HonFu
HonFu - avatar
0
I used return statement
13th Nov 2019, 6:51 AM
Gnana Divya
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
24th Mar 2021, 6:50 AM
sravanthi
sravanthi - avatar